Flutter 颤振:ShowDialog不使用ListTile的OnTap()方法

Flutter 颤振:ShowDialog不使用ListTile的OnTap()方法,flutter,dart,showdialog,Flutter,Dart,Showdialog,我正在使用抽屉创建一个菜单,其中包含选项的ListTiles。我想在用户点击瓷砖时创建一个弹出窗口。当前,即使在showDialog之后有一个Navigator.pop(),当点击磁贴时,代码也不会显示任何内容 //包含有问题的ListTile的抽屉 抽屉( 子:ListView( 填充:EdgeInsets.zero, 儿童:[ 抽屉阅读器( 子项:文本(“粉碎跟踪器”), ), ), 列表砖( 标题:正文( “关于”, 样式:TextStyle( fontFamily:“粉碎”, 字体大小:

我正在使用抽屉创建一个菜单,其中包含选项的ListTiles。我想在用户点击瓷砖时创建一个弹出窗口。当前,即使在showDialog之后有一个Navigator.pop(),当点击磁贴时,代码也不会显示任何内容

//包含有问题的ListTile的抽屉
抽屉(
子:ListView(
填充:EdgeInsets.zero,
儿童:[
抽屉阅读器(
子项:文本(“粉碎跟踪器”),
),
),
列表砖(
标题:正文(
“关于”,
样式:TextStyle(
fontFamily:“粉碎”,
字体大小:15.0,
颜色:颜色。来自RGBO(77、114、152、1.0),
),
),
onTap:(){
//显示弹出窗口
showDialog(上下文:上下文,子项:
新建警报对话框(
标题:新文本(
“关于”,
样式:TextStyle(fontFamily:“Smash”),
),
内容:新文本(
“这是占位符。这是占位符。这是占位符。这是占位符。”,
样式:TextStyle(fontFamily:“Smash”),
),
)
);
//不跑
Navigator.pop(上下文);
},
),
下面是一个演示:


其他ListTile的onTap()方法中只有have Navigator.pop()。对话框没有显示,因为您正在使用
Navigator.pop(context)
立即弹出该对话框。您可以
等待
对话框,因为它在弹出之前返回
Future

我以您的小部件树为例添加了一个演示:

Drawer(
        child: ListView(
          padding: EdgeInsets.zero,
          children: <Widget>[
            DrawerHeader(
              child: Text('Smash Tracker'),
            ),
            ListTile(
              title: Text(
                'About',
                style: TextStyle(
                  fontFamily: 'Smash',
                  fontSize: 15.0,
                  color: Color.fromRGBO(77, 114, 152, 1.0),
                ),
              ),
              onTap: () async { // mark the function as async
                print('tap');
                // Show PopUp

                // await the dialog
                 await showDialog(
                    context: context,
                    child: new AlertDialog(
                      title: new Text(
                        'About',
                        style: TextStyle(fontFamily: "Smash"),
                      ),
                      content: new Text(
                        'This is a placeholder. This is a placeholder. This is a placeholder. This is a placeholder.',
                        style: TextStyle(fontFamily: "Smash"),
                      ),
                    ));

                // Doesn't run
                Navigator.pop(context);
              },
            ),
          ],
        ),
      ),
抽屉(
子:ListView(
填充:EdgeInsets.zero,
儿童:[
抽屉阅读器(
子项:文本(“粉碎跟踪器”),
),
列表砖(
标题:正文(
“关于”,
样式:TextStyle(
fontFamily:“粉碎”,
字体大小:15.0,
颜色:颜色。来自RGBO(77、114、152、1.0),
),
),
onTap:()async{//将函数标记为async
打印(“点击”);
//显示弹出窗口
//等待对话
等待显示对话框(
上下文:上下文,
子:新建警报对话框(
标题:新文本(
“关于”,
样式:TextStyle(fontFamily:“Smash”),
),
内容:新文本(
“这是占位符。这是占位符。这是占位符。这是占位符。”,
样式:TextStyle(fontFamily:“Smash”),
),
));
//不跑
Navigator.pop(上下文);
},
),
],
),
),
输出:


为什么在
showdialog
之后使用
Navigator.pop()
?它被用来回答一个我认为与我的问题类似的问题。首先执行
Navigator.pop()
关闭抽屉,然后调用
showdialog
我移动了
Navigator.pop()
显示对话框上方,它只关闭抽屉,没有弹出窗口。
Drawer(
        child: ListView(
          padding: EdgeInsets.zero,
          children: <Widget>[
            DrawerHeader(
              child: Text('Smash Tracker'),
            ),
            ListTile(
              title: Text(
                'About',
                style: TextStyle(
                  fontFamily: 'Smash',
                  fontSize: 15.0,
                  color: Color.fromRGBO(77, 114, 152, 1.0),
                ),
              ),
              onTap: () async { // mark the function as async
                print('tap');
                // Show PopUp

                // await the dialog
                 await showDialog(
                    context: context,
                    child: new AlertDialog(
                      title: new Text(
                        'About',
                        style: TextStyle(fontFamily: "Smash"),
                      ),
                      content: new Text(
                        'This is a placeholder. This is a placeholder. This is a placeholder. This is a placeholder.',
                        style: TextStyle(fontFamily: "Smash"),
                      ),
                    ));

                // Doesn't run
                Navigator.pop(context);
              },
            ),
          ],
        ),
      ),