美文网首页
Flutter中 Dialog 、Toast 、Loading

Flutter中 Dialog 、Toast 、Loading

作者: 苦咖啡Li | 来源:发表于2020-10-04 11:28 被阅读0次
1、 Dialog 弹框

AlertDialog Material 风格:

      showDialog(
          context: context,
          builder: (context) {
              return AlertDialog(
                  title: Text('提示'),
                  content: Text('确认删除吗?'),
                  backgroundColor: Colors.lightBlueAccent,
                  shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
                  actions: <Widget>[
                      FlatButton(child: Text('取消'),onPressed: (){
                          Navigator.of(context).pop('cancel');
                      },),
                      FlatButton(child: Text('确认'),onPressed: (){
                          Navigator.of(context).pop('ok');
                      },),
                  ],
              );
          },
      );

CupertinoAlertDialog IOS 的风格:

        showCupertinoDialog(
            context: context,
            builder: (context) {
                return CupertinoAlertDialog(
                    title: Text('提示'),
                    content: Text('确认删除吗?'),
                    actions: <Widget>[
                    CupertinoDialogAction(child: Text('取消'),onPressed: (){},),
                    CupertinoDialogAction(child: Text('确认'),onPressed: (){},),
                    ],
                );
            }
        );

SimpleDialog 用法和 AlertDialog 基本相同

       showDialog(
           context: context,
           builder: (context) {
           return SimpleDialog(
               title: Text('提示'),
               children: <Widget>[
               Container(
                   height: 80,
                   alignment: Alignment.center,
                   child: Text('确认删除吗?'),
               ),
               Divider(height: 1,),
               FlatButton(
                   child: Text('取消'),
                   onPressed: () {
                   Navigator.of(context).pop('cancel');
                   },
               ),
               Divider(height: 1,),
               FlatButton(
                   child: Text('确认'),
                   onPressed: () {
                   Navigator.of(context).pop('ok');
                   },
               ),
               ],
           );
           },
       );
2、 Toast 提示

2.1 pubspec.yaml 中添加 fluttertoast

     fluttertoast: ^3.1.3

2.2 在使用的组件文件中 引入该文件包、或者在公共组件中重新封装成你想要的样式

        package:'fluttertoast/fluttertoast.dart';

        Fluttertoast.showToast(
            msg: 'Toast  提示',
           // 时间长短Toast.LENGTH_SHORT(2500ms)、Toast.LENGTH_LONG(3500ms)
            toastLength: Toast.LENGTH_SHORT,
            // 消息框弹出的位置  (上中下)ToastGravity.TOP、ToastGravity.CENTER、 ToastGravity.BOTTOM
            gravity: ToastGravity.CENTER,  
            // 消息框持续的时间(目前的版本只有ios有效)
            timeInSecForIos: 1,  
            backgroundColor: Colors.red,
            textColor: Colors.white,
            fontSize: 16.0
        );
3、 Loading 加载框 flutter_easyloading: ^1.1.3

相关文章

网友评论

      本文标题:Flutter中 Dialog 、Toast 、Loading

      本文链接:https://www.haomeiwen.com/subject/patluktx.html