Flutter教学

Flutter(25):Material组件之AlertDial

2020-09-30  本文已影响0人  starryxp

Flutter教学目录持续更新中

Github源代码持续更新中

1.AlertDialog介绍

一个会中断用户操作的对话款,需要用户确认

2.AlertDialog属性

3.AlertDialog

1601448272(1).png
class _AlertDialogPageState extends State<AlertDialogPage> {
  AlertDialog _dialog;

  _createAlertDialog() {
    return AlertDialog(
      title: Text(
        '我是标题',
        textAlign: TextAlign.center,
      ),
      titlePadding: EdgeInsets.all(10),
      titleTextStyle: TextStyle(
        fontSize: 16,
        fontWeight: FontWeight.bold,
        color: Colors.blue,
      ),
      content: SingleChildScrollView(
        child: Container(
          child: Column(
            children: [
              Text('内容1'),
              Text('内容2'),
            ],
          ),
        ),
      ),
      contentTextStyle: TextStyle(
        fontSize: 14,
        fontWeight: FontWeight.normal,
        color: Colors.black,
      ),
      actions: [
        RaisedButton(
          onPressed: () {
            Navigator.of(context).pop();
          },
          child: Text('取消'),
        ),
        RaisedButton(
          onPressed: () {
            Navigator.of(context).pop();
          },
          child: Text('确定'),
        ),
      ],
      actionsPadding: EdgeInsets.all(10),
      actionsOverflowButtonSpacing: 10,
      backgroundColor: Colors.white,
      elevation: 10,
      clipBehavior: Clip.antiAlias,
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(5),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('AlertDialog'),
      ),
      body: ListView(
        padding: EdgeInsets.all(10),
        children: [
          RaisedButton(
            onPressed: () {
              if (_dialog == null) {
                _dialog = _createAlertDialog();
              }
              showDialog(
                context: context,
                builder: (context) {
                  return _dialog;
                },
              );
            },
            child: Text('打开AlertDialog'),
          )
        ],
      ),
    );
  }
}

下一节:Material组件之BottomSheet

Flutter(26):Material组件之BottomSheet

Flutter教学目录持续更新中

Github源代码持续更新中

上一篇下一篇

猜你喜欢

热点阅读