Flutter:Dialog对话框及自定义Dialog

基本属性介绍

几个自带的dialog用法和属性基本一致,只是部分参数不同

const AlertDialog({
   
  Key? key,
  this.title, //对话框标题组件
  this.titlePadding, // 标题填充
  this.titleTextStyle, //标题文本样式
  this.content, // 对话框内容组件
  this.contentPadding = const EdgeInsets.fromLTRB(24.0, 20.0, 24.0, 24.0), //内容的填充
  this.contentTextStyle,// 内容文本样式
  this.actions, // 对话框操作按钮组
  this.backgroundColor, // 对话框背景色
  this.elevation,// 对话框的阴影
  this.semanticLabel, //对话框语义化标签(用于读屏软件)
  this.shape, // 对话框外形
})

显示dialog:
showDialog:

Future<T?> showDialog<T>({
   
  required BuildContext context,
  required WidgetBuilder builder,//需要显示的弹窗
  bool barrierDismissible = true,//点击背后蒙层是否关闭弹框,默认为 true
  Color? barrierColor = Colors.black54,//背后蒙层颜色
  String? barrierLabel,
  bool useSafeArea = true,//是否使用安全区域,默认为 true
  bool useRootNavigator = true,//是否使用根导航,默认为 true
  RouteSettings? routeSettings,//路由设置
}) 

showCupertinoDialog 也是控制 Dialog 弹出的 api。其实与 showDialog
一样,两者都可以调用各种弹框,但是 showCupertinoDialog 默认是不可以点击空白区域隐藏的。

Future<T?> showCupertinoDialog<T>({
   
  required BuildContext context,
  required WidgetBuilder builder,//需要显示的弹窗
  String? barrierLabel,
  bool useRootNavigator = true,//是否使用根导航,默认为 true
  bool barrierDismissible = false,//点击背后蒙层是否关闭弹框,默认为 false
  RouteSettings? routeSettings,//路由设置
})

1.AlertDialog确认对话框

  _alertDialog() async{
   
    var result= await showDialog(
        barrierDismissible:false,   //表示点击灰色背景的时候是否消失弹出框
        context:context,
        builder: (context){
   
          return AlertDialog(
            title: Text("提示信息!"),
            content:Text("您确定要删除吗?") ,
            actions: <Widget>[
              TextButton(
                child: Text("取消"),
                onPressed: (){
   
                  print("取消");
                  Navigator.pop(context,'Cancle');//点击之后使这个页面消失
                },
              ),
              TextButton(
                child: Text(
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值