zoukankan      html  css  js  c++  java
  • 29 Flutter Dialog AlertDialog 、SimpleDialog、showModalBottomSheet、showToast

    pubspec.yaml

     fluttertoast: ^3.1.3

    Dialog.dart

    import 'package:flutter/material.dart';
    import 'package:fluttertoast/fluttertoast.dart';
    
    class DialogPage extends StatefulWidget {
      DialogPage({Key key}) : super(key: key);
    
      _DialogPageState createState() => _DialogPageState();
    }
    
    class _DialogPageState extends State<DialogPage> {
      _alertDialog() async {
        var result = await showDialog(
            context: context,
            builder: (context) {
              return AlertDialog(
                title: Text('提示信息'),
                content: Text('你确定要删除吗?'),
                actions: <Widget>[
                  FlatButton(
                    child: Text('取消'),
                    onPressed: () {
                      print('取消');
                      Navigator.pop(context, "Cancle");
                    },
                  ),
                  FlatButton(
                    child: Text('确定'),
                    onPressed: () {
                      Navigator.pop(context, "Ok");
                      print('确定');
                    },
                  )
                ],
              );
            });
        print(result);
      }
    
      _simpleDialog() async {
        var result = await showDialog(
            context: context,
            builder: (context) {
              return SimpleDialog(
                title: Text("选择内容"),
                children: <Widget>[
                  SimpleDialogOption(
                    child: Text("Option A"),
                    onPressed: () {
                      print("Options A");
                      Navigator.pop(context, "A");
                    },
                  ),
                  Divider(),
                  SimpleDialogOption(
                    child: Text("Option B"),
                    onPressed: () {
                      print("Options B");
                      Navigator.pop(context, "B");
                    },
                  ),
                  Divider(),
                  SimpleDialogOption(
                    child: Text("Option C"),
                    onPressed: () {
                      print("Options C");
                      Navigator.pop(context, "C");
                    },
                  )
                ],
              );
            });
        print(result);
      }
    
      _modelBottomSheet() async {
        showModalBottomSheet(
            context: context,
            builder: (context) {
              return Container(
                height: 220,
                child: Column(
                  children: <Widget>[
                    ListTile(
                      title: Text("分享 A"),
                      onTap: () {
                        print("分享 A");
                        Navigator.pop(context, "A");
                      },
                    ),
                    Divider(),
                    ListTile(
                      title: Text("分享 B"),
                      onTap: () {
                        print("分享 B");
                        Navigator.pop(context, "B");
                      },
                    ),
                    Divider(),
                    ListTile(
                      title: Text("分享 C"),
                      onTap: () {
                        print("分享 C");
                        Navigator.pop(context, "C");
                      },
                    )
                  ],
                ),
              );
            });
      }
    
      _toast() async {
        Fluttertoast.showToast(
          msg:'提示信息',
          toastLength: Toast.LENGTH_SHORT,
          gravity: ToastGravity.CENTER,
          timeInSecForIos: 3,
          backgroundColor: Colors.black87,
          textColor: Colors.white,
          fontSize: 16.0
        );
      }
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text('Dialog'),
          ),
          body: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                RaisedButton(
                  child: Text('alert弹出框-AlertDialog'),
                  onPressed: _alertDialog,
                ),
                SizedBox(height: 20),
                RaisedButton(
                  child: Text('select弹出框-SimpleDialog'),
                  onPressed: _simpleDialog,
                ),
                SizedBox(height: 20),
                RaisedButton(
                  child: Text('ActionSheet弹出框-showModalBottomSheet'),
                  onPressed: _modelBottomSheet,
                ),
                SizedBox(height: 20),
                RaisedButton(
                  child: Text('toast-fluttertoast第三方库'),
                  onPressed: _toast,
                ),
              ],
            ),
          ),
        );
      }
    }

  • 相关阅读:
    Jzoj4822 完美标号
    Jzoj4822 完美标号
    Jzoj4792 整除
    Jzoj4792 整除
    Educational Codeforces Round 79 A. New Year Garland
    Good Bye 2019 C. Make Good
    ?Good Bye 2019 B. Interesting Subarray
    Good Bye 2019 A. Card Game
    力扣算法题—088扰乱字符串【二叉树】
    力扣算法题—086分隔链表
  • 原文地址:https://www.cnblogs.com/yiweiyihang/p/11568477.html
Copyright © 2011-2022 走看看