选择一个选项后如何在flutter中关闭SimpleDialog

Rab*_*adi 3 android simpledialog flutter

我添加了SimpleDialog2 个选项:失物招领。每当我做出选择并被重定向到我想要的位置时,SimpleDialog 不会关闭并停留在我的屏幕上。

开关:

switch (
  await showDialog(
    context: context,
    child: new SimpleDialog(
      title: new Text("Which category?"),
      children: <Widget>[
        new SimpleDialogOption(child: new Text("Found"),
          onPressed: () {
            goToCreate();
          },
        ),
        new SimpleDialogOption(child: new Text("Lost"),
          onPressed: () {
            //Whatever
          },
        ),
      ],
    )
  )
)
Run Code Online (Sandbox Code Playgroud)

和案例:

{
  case "Found":
    goToCreate();
    break;
  case "Lost":
    //Whatever
    break;
}
Run Code Online (Sandbox Code Playgroud)

Mar*_*yns 5

当您按“接受”(或其他任何方式)时,您可以从对话框中执行此操作:

Navigator.pop(context, true); // You could return any Dart type, like an enum
Run Code Online (Sandbox Code Playgroud)

来自来电者:

bool dialogReturnValue = await showDialog(...);
if (dialogReturnValue == true){
    // do something
}
Run Code Online (Sandbox Code Playgroud)