封装dialog_常用 Widget 详解-Dialog

978b76eb7974ae50b7b18bddf0521eb9.png

SimpleDialog

A simple material design dialog.

这是一种非常灵活的 Dialog 完全需要你根据自己的需求,来完成它的绘制。

import 'package:flutter/material.dart';

class AVDialog extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('AVAlertDialog'),
      ),
      body: new RaisedButton(
        child: new Text('click me'),
        color: Colors.green,
        onPressed: (){
          showDialog(
            context: context,
            child: new SimpleDialog(
              title: new Text('Hello icepy'),
              children: <Widget>[
                new Text('dialog children')
              ],
            )
          );
        },
      ),
    );
  }
}

0e4a20b3d219e5a713a7f1efc9c76d1f.gif

AlertDialog

A material design alert dialog.

顾名思义这是一种比 SimpleDialog 封装程度更高的 Dialog ,一般情况下如果你的用户需要完成确认这一项功能,那么使用它会比较迅速。

import 'package:flutter/material.dart';

class AVDialog extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('AVDialog'),
      ),
      body: new RaisedButton(
        child: new Text('click me'),
        color: Colors.green,
        onPressed: (){
          showDialog(
            context: context,
            child: new AlertDialog(
              title: new Text('alert'),
              actions: <Widget>[
                new FlatButton(
                  child: new Text('确定'),
                  onPressed: (){
                    Navigator.pop(context);
                  },
                )
              ],
            )
          );
        },
      ),
    );
  }
}

2eb05d84ec3acbcc1472e729e1ec27a9.gif

AboutDialog

An about box. This is a dialog box with the application's icon, name, version number, and copyright, plus a button to show licenses for software used by the application.

这个 Widget 一般来说不是很常用,只用于显示应用,如图:

dd246478a254c7432531a806fd91ff46.gif
import 'package:flutter/material.dart';

class AVDialog extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('AVDialog'),
      ),
      body: new RaisedButton(
        child: new Text('click me'),
        color: Colors.green,
        onPressed: (){
          showDialog(
            context: context,
            child: new AboutDialog(
              applicationName: 'Flutter',
              applicationVersion: 'v1.0.0',
              applicationIcon: new Icon(
                Icons.android,
                color: Colors.green,
              ),
              children: <Widget>[
                new Text(
                  '更新摘要 n Update 1.0.0'
                )
              ],
            )
          );
        },
      ),
    );
  }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值