zl程序教程

您现在的位置是:首页 >  移动开发

当前栏目

flutter 弹窗

flutter 弹窗
2023-09-14 09:04:29 时间

参考
AlertDialog

new MaterialButton(
    color: Colors.blue,
    child: new Text('点我'),
    onPressed: () {
        showDialog<Null>(
            context: context,
            barrierDismissible: false,
            builder: (BuildContext context) {
                return new AlertDialog(
                    title: new Text('标题'),
                    content: new SingleChildScrollView(
                        child: new ListBody(
                            children: <Widget>[
                                new Text('内容 1'),
                                new Text('内容 2'),
                            ],
                        ),
                    ),
                    actions: <Widget>[
                        new FlatButton(
                            child: new Text('确定'),
                            onPressed: () {
                                Navigator.of(context).pop();
                            },
                        ),
                    ],
                );
            },
        ).then((val) {
            print(val);
        });
    },
),

SimpleDialog

new MaterialButton(
    color: Colors.blue,
    child: new Text('点我'),
    onPressed: () {
        showDialog<Null>(
            context: context,
            builder: (BuildContext context) {
                return new SimpleDialog(
                    title: new Text('选择'),
                    children: <Widget>[
                        new SimpleDialogOption(
                            child: new Text('选项 1'),
                            onPressed: () {
                                Navigator.of(context).pop();
                            },
                        ),
                        new SimpleDialogOption(
                            child: new Text('选项 2'),
                            onPressed: () {
                                Navigator.of(context).pop();
                            },
                        ),
                    ],
                );
            },
        ).then((val) {
            print(val);
        });
    },
),

这个是我代码里面的

  Container(
                        margin: const EdgeInsets.only(left: 40.0, right: 40.0),
                        child: ElevatedButton(
                          onPressed: () {
                            showDialog<Null>(
                              context: context,
                              barrierDismissible: false,
                              builder: (BuildContext context) {
                                return AlertDialog(
                                  title: const Text('标题'),
                                  content: SingleChildScrollView(
                                    child: ListBody(
                                      children: const <Widget>[
                                        Text('确定关注该歌手吗'),
                                        Text('内容 2'),
                                      ],
                                    ),
                                  ),
                                  actions: <Widget>[
                                    FlatButton(
                                      child: const Text('确定'),
                                      onPressed: () {
                                        Navigator.of(context).pop();
                                      },
                                    ),
                                  ],
                                );
                              },
                            ).then((val) {
                              print(val);
                            });
                          },
                          child: const Text("+ 关注"),
                        ),
                      ),