【问题标题】:Alert Dialog on onTap on ListTileListTile 中 onTap 上的警报对话框
【发布时间】:2020-04-12 22:27:16
【问题描述】:

如何通过单击/点击 ListTile 来创建 AlertDialog。 目前我正在这样做,点击它时没有任何反应。

body: ListView(
        children: <Widget>[
          ListTile(
            title: Text('Theme'),
            onTap: (){
              AlertDialog(
                title: Text('Hi'),
              );
            },
          )
        ],
      ),

PS:我是菜鸟,请放轻松。

【问题讨论】:

    标签: flutter flutter-layout


    【解决方案1】:

    你很亲密,你创建了对话框,只需要显示它:

    body: ListView(
            children: <Widget>[
              ListTile(
                title: Text('Theme'),
                onTap: () {
                  AlertDialog alert = AlertDialog(
                    title: Text('Hi'),
                  );
                  showDialog(
                    context: context,
                    builder: (BuildContext context) {
                      return alert;
                    },
                  );
                },
              )
            ],
          ),
    

    【讨论】:

      【解决方案2】:

      用这个改变你的ListTile

      ListTile(
        title: Text('Theme'),
        onTap: () {
          showDialog(
              context: context,
              builder: (context) {
                return AlertDialog(
                  title: Text('Alert Dialog Example'),
                  content: Text('Alert Dialog Body Goes Here  ..'),
                  actions: <Widget>[
                    FlatButton(
                        onPressed: () => Navigator.of(context).pop(),
                        child: Text('OK')),
                  ],
                );
              });
        },
      )
      

      我还添加了一些属性来使用AlertDialog(),例如titlecontentactions

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-02-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多