Flutter 之 Dialog 控件

AlertDialog

void _showAlertDialog() {
    showDialog(
        context: context,
        //对话框以外是否可以点击消失弹框
        barrierDismissible: true,
        builder: (BuildContext context) {
          return new AlertDialog(
            title: new Text('弹框标题'),
            //可滑动
            content: new Text('弹框内容'),
            actions: [
              new FlatButton(
                child: new Text('取消'),
                onPressed: () {
                  Navigator.of(context).pop();
                },
              ),
              new FlatButton(
                child: new Text('确定'),
                onPressed: () {
                  Navigator.of(context).pop();
                },
              ),
            ],
          );
        });
  }

SimpleDialog

void _showSimpleDialog() {
    showDialog(
      context: context,
      builder: (BuildContext context) {
        return new SimpleDialog(
          title: new Text('选择性别'),
          children: [
            new SimpleDialogOption(
              child: new Text('男'),
              onPressed: () {
                Navigator.of(context).pop();
              },
            ),
            new SimpleDialogOption(
              child: new Text('女'),
              onPressed: () {
                Navigator.of(context).pop();
              },
            ),
            new SimpleDialogOption(
              child: new Text('保密'),
              onPressed: () {
                Navigator.of(context).pop();
              },
            ),
          ],
        );
      },
    );
  }

CupertinoAlertDialog

void _showIOSDialog(BuildContext cxt) {
    showCupertinoDialog(
        context: cxt,
        builder: (cxt) {
          return new CupertinoAlertDialog(
            title: Text('提示'),
            content: Text('是否退出应用'),
            actions: [
              new Container(
                decoration: BoxDecoration(
                    border: Border(
                        right: BorderSide(color: Color(0xFFD9D9D9), width: 0.5),
                        top: BorderSide(color: Color(0xFFD9D9D9), width: 0.5))),
                child: CupertinoDialogAction(
                  child: new Text("确定"),
                  onPressed: () {
                    Navigator.pop(context);
                  },
                ),
              ),
              new Container(
                decoration: BoxDecoration(
                    border: Border(
                        top: BorderSide(color: Color(0xFFD9D9D9), width: 0.5))),
                child: CupertinoDialogAction(
                  child: new Text("取消"),
                  onPressed: () {
                    Navigator.pop(context);
                  },
                ),
              )
            ],
          );
        });
  }

你可能感兴趣的:(Flutter 之 Dialog 控件)