title: Flutter : Waiting for response of an alert dialog inside onWillAccept function of DragTarget
body: <p>I have recently started learning Flutter and I am stuck at a point while dealing with Drag and Drop using Droppable and DragTarget. When I Drag my draggable element over DropTarget element, I am doing few validations in <em>onWillAccept</em> method. One of the conditions here requires me to confirm with user if they are willing to continue with their action before returning <em>true</em> and heading to <em>onAccept</em> method. For some reason, code execution does not wait for user's action to return. </p>
  
  <p>This is how my DragTarget looks</p>
  
  <pre><code>DragTarget&lt;Map&gt;(
    builder: (context, listOne, listTwo) {
      return Container();
    },
    onWillAccept: (value) {
      if(condition1) {
        return true;
      } else if(condition2) {
        return true;
      } else {
        if(!condition3) {
          return true;
        } else {
          await _showConfirmation();
          return false;
        }
      }
    },
    onAccept: (value) {
      print(value);
    },
  )
  </code></pre>
  
  <p>and <em>_showConfirmation</em> method looks something like this </p>
  
  <pre><code>Future&lt;void&gt; _showConfirmation() async {
    return showDialog&lt;void&gt;(
      context: context,
      barrierDismissible: false,
      builder: (BuildContext context) {
        return AlertDialog(
          title: Text('Attention'),
          content: SingleChildScrollView(
            child: ListBody(
              children: &lt;Widget&gt;[
                Text('Some message")
              ],
            ),
          ),
          actions: &lt;Widget&gt;[
            FlatButton(
              child: Text('Accept'),
              onPressed: () {
                Navigator.of(context).pop();
                return true;
              },
            ),
            FlatButton(
              child: Text('Cancel'),
              onPressed: () {
                Navigator.of(context).pop();
                return false;
              },
            )
          ],
        );
      },
    );
  }
  </code></pre>
  
  <p>Adding await does not help as onWillAccept is not async. Making it async did not help either. </p>
  
  <pre><code>_showConfirmation().then((result) {
    return result
  })
  </code></pre>
  
  <p>Above code did not help either. In many cases, the dragged item is left hanging over DragTarget box.</p>
  
  <p>Any help regarding this will appreciated, thank you.</p>