Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 颤振:等待DragTarget的onWillAccept函数内警报对话框的响应_Flutter_Dart_Promise_Drag And Drop_Flutter Alertdialog - Fatal编程技术网

Flutter 颤振:等待DragTarget的onWillAccept函数内警报对话框的响应

Flutter 颤振:等待DragTarget的onWillAccept函数内警报对话框的响应,flutter,dart,promise,drag-and-drop,flutter-alertdialog,Flutter,Dart,Promise,Drag And Drop,Flutter Alertdialog,我最近开始学习颤振,在使用Droppable和DragTarget处理拖放操作时,我陷入了困境。当我将我的Dragable元素拖到DropTarget元素上时,我在onWillAccept方法中进行了一些验证。这里的一个条件要求我与用户确认他们是否愿意在返回true并转到onAccept方法之前继续操作。出于某种原因,代码执行不会等待用户的操作返回 这就是我的DragTarget的外观 DragTarget<Map>( builder: (context, listOne, li

我最近开始学习颤振,在使用Droppable和DragTarget处理拖放操作时,我陷入了困境。当我将我的Dragable元素拖到DropTarget元素上时,我在onWillAccept方法中进行了一些验证。这里的一个条件要求我与用户确认他们是否愿意在返回true并转到onAccept方法之前继续操作。出于某种原因,代码执行不会等待用户的操作返回

这就是我的DragTarget的外观

DragTarget<Map>(
  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);
  },
)
上面的代码也没有帮助。在许多情况下,拖动的项目悬空在DragTarget框上


感谢您提供的任何帮助。

您确定Dart支持
wait
?我不懂这种语言,但可以找到证据证明它的未来有
.then()
.catchError()
方法。Dart确实支持async/await。根据我的上一个代码块,我也使用了.then(),但它并没有产生预期的结果OK。在这种情况下,问题似乎是
onWillAccept
函数预期返回
true
(或者可能是任何truthy)或者
false
(或者可能是任何falsy)。在上一行的
wait
之后,它将返回
,这是真实的。除了提交拉取请求之外,我看不出您如何解决这个问题。您可以尝试忽略
onWillAccept
中的
condition3
,即
else{return true}
然后在
onAccept
处理程序中的
condition3
。不确定如何在Dart中执行此操作,但您可能还需要根据传递给接受的值是否为
进行分支。可能不是您想要的,但可能会激发思考。您确定Dart支持
wait
?我不懂这种语言,但可以找到证据证明它的未来有
.then()
.catchError()
方法。Dart确实支持async/await。根据我的上一个代码块,我也使用了.then(),但它并没有产生预期的结果OK。在这种情况下,问题似乎是
onWillAccept
函数预期返回
true
(或者可能是任何truthy)或者
false
(或者可能是任何falsy)。在上一行的
wait
之后,它将返回
,这是真实的。除了提交拉取请求之外,我看不出您如何解决这个问题。您可以尝试忽略
onWillAccept
中的
condition3
,即
else{return true}
然后在
onAccept
处理程序中的
condition3
。不确定如何在Dart中执行此操作,但您可能还需要根据传递给接受的值是否为
进行分支。可能不是你想要的,但可能会激发你的思考。
Future<void> _showConfirmation() async {
  return showDialog<void>(
    context: context,
    barrierDismissible: false,
    builder: (BuildContext context) {
      return AlertDialog(
        title: Text('Attention'),
        content: SingleChildScrollView(
          child: ListBody(
            children: <Widget>[
              Text('Some message")
            ],
          ),
        ),
        actions: <Widget>[
          FlatButton(
            child: Text('Accept'),
            onPressed: () {
              Navigator.of(context).pop();
              return true;
            },
          ),
          FlatButton(
            child: Text('Cancel'),
            onPressed: () {
              Navigator.of(context).pop();
              return false;
            },
          )
        ],
      );
    },
  );
}
_showConfirmation().then((result) {
  return result
})