Flutter 颤振底部导航栏等待异步功能

Flutter 颤振底部导航栏等待异步功能,flutter,async-await,dialog,navigation-drawer,Flutter,Async Await,Dialog,Navigation Drawer,我在StatefulWidget中有一个底部导航栏,还有一个带有3个选项的对话框:打开相机、画廊或取消 这是我的密码: 导航栏 Widget build(BuildContext context) { return new Scaffold( body: PageView( children: [ Container( color: Colors.white,child: HomePage(),),

我在StatefulWidget中有一个底部导航栏,还有一个带有3个选项的对话框:打开相机、画廊或取消

这是我的密码: 导航栏

Widget build(BuildContext context) {
    return new Scaffold(
      body: PageView(
        children: [
          Container(
            color: Colors.white,child: HomePage(),),
          Container(
            color: Colors.white,child: AddPost(),),
        ],
        controller: pageController,
        physics: NeverScrollableScrollPhysics(),
        onPageChanged: onPageChanged,
      ),
      bottomNavigationBar: CupertinoTabBar(
        backgroundColor: Colors.white,
        items: <BottomNavigationBarItem>[
          BottomNavigationBarItem(
              icon: Icon(Icons.home,
              title: Container(height: 0.0),
              backgroundColor: Colors.white),
          BottomNavigationBarItem(
              icon: Icon(Icons.add_circle,
              title: Container(height: 0.0),
          )
        ],
        onTap: navigationTapped,
        currentIndex: _page,
      ),
    );
  }
如何等待用户点击导航栏选择选项


提前谢谢

在您的
\u selectImage
功能中,您可以等待对话框关闭,然后执行如下代码:

等待显示对话框(
上下文:上下文,
barrierDismissible:false,//用户必须点击按钮!
生成器:(BuildContext上下文){
返回SimpleDialog(
标题:const Text(“创建帖子”),
儿童:[
简单幻觉(
child:const Text(“拍照”),
onPressed:()异步{
Navigator.pop(上下文);
File imageFile=wait ImagePicker.pickImage(来源:ImageSource.camera,最大宽度:1920,最大高度:1200,图像质量:80);
设置状态(){
file=imageFile;
});
}),
简单幻觉(
子项:常量文本(“从库中选择”),
onPressed:()异步{
Navigator.of(context.pop();
File imageFile=wait ImagePicker.pickImage(来源:ImageSource.gallery,最大宽度:1920,最大高度:1200,图像质量:80);
设置状态(){
file=imageFile;
});
}),
简单幻觉(
子项:常量文本(“取消”),
已按下:(){
Navigator.pop(上下文);
},
)
],
);
},
).然后((onValue){
如果(onValue!=null){
///你想做的代码
}
});
可使用此功能设置
onValue

Navigator.pop(上下文,值youwanttoreturn);
如果即使
onValue
为空(
Navigator.pop(context)
),也要执行某些代码,请删除该条件

  File file;
  _selectImage( ) async {
    return showDialog<Null>(
      context: context,
      barrierDismissible: false, // user must tap button!
      builder: (BuildContext context) {
        return SimpleDialog(
          title: const Text('Create a Post'),
          children: <Widget>[
            SimpleDialogOption(
                child: const Text('Take a photo'),
                onPressed: () async {
                  Navigator.pop(context);
                  File imageFile =
                      await ImagePicker.pickImage(source: ImageSource.camera, maxWidth: 1920, maxHeight: 1200, imageQuality: 80);
                  setState(() {
                    file = imageFile;
                  });
                }),
            SimpleDialogOption(
                child: const Text('Choose from Gallery'),
                onPressed: () async {
                  Navigator.of(context).pop();
                  File imageFile =
                      await ImagePicker.pickImage(source: ImageSource.gallery, maxWidth: 1920, maxHeight: 1200, imageQuality: 80);
                  setState(() {
                    file = imageFile;
                  });
                }),
            SimpleDialogOption(
              child: const Text("Cancel"),
              onPressed: () {
                Navigator.pop(context);
              },
            )
          ],
        );
      },
    );
  }
void navigationTapped(int page) async{
    if(page != 1){
      pageController.jumpToPage(page);
    }else{
      await _selectImage(); //opens dialog
    }
    //Handle button tap
  }