如何在Flutter中等待调用后显示AlertDialog

时间:2018-04-13 15:00:48

标签: dart flutter

由于一些奇怪的原因,我在AlertDialog电话后无法显示await。对话框刚好拒绝出现。但是,如果我注释掉await来电,则会显示对话框。

void selectImage() async {
    var _fileName = await ImagePicker.pickImage(
        source: ImageSource.gallery, maxWidth: 250.0, maxHeight: 250.0);

    showDialog(
        context: context,
        builder: (BuildContext context) => new AlertDialog(
          content: new Text("Random question?"),
          actions: <Widget>[
            new FlatButton(
                onPressed: () => Navigator.pop(context),
                child: const Text("NO")),
            new FlatButton(
                onPressed: (() {
                  Navigator.pop(context);
                  setState(() {
                    imageFile = _fileName;
                  });
                }),
                child: const Text("YES"))
          ],
        ));

}

拜托,我做错了什么?

0 个答案:

没有答案