zoukankan      html  css  js  c++  java
  • AlertDialog 、SimpleDialog、 showModalBottomSheet、showToast 自定义 Dialog

    // AlertDialog 、SimpleDialog、showModalBottomSheet、showToast
    // 使用showToast安装插件 https://pub.dev/packages/fluttertoast
    Fluttertoast.showToast( msg: "This is Short Toast", toastLength: Toast.LENGTH_SHORT, timeInSecForIos: 1);

    // 改变弹窗内的值
    StatefulBuilder(
    builder: (context, changeState) {
    return '内容'
    },
    )
    // 点击背景消失
    showDialog(
    context: context,
    builder: (context) {
    return CupertinoDialog (
    child: Text('zxcvbnm123456', style: TextStyle(fontSize: Screen.width(30), decoration: TextDecoration.none, color: Colors.black, fontWeight: FontWeight.normal)));
    }
    );
    // 点击背景不消失
    showCupertinoDialog(
    context: context,
    builder: (context) {
    return CupertinoDialog (
    child: Text('zxcvbnm123456', style: TextStyle(fontSize: Screen.width(30), decoration: TextDecoration.none, color: Colors.black, fontWeight: FontWeight.normal)));
    }
    );

    import 'package:flutter/material.dart';
    import 'myDialog.dart';

    class DialogPage extends StatefulWidget{
    DialogPage({Key key});
    _Dialog createState() => _Dialog();
    }

    class _Dialog extends State {
    @override
    Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
    appBar: AppBar(
    title: Text('Dialog')
    ),
    body: ListView(
    children: <Widget>[
    RaisedButton(
    child: Text('AlertDialog'),
    onPressed: () {
    showDialog(
    context: context,
    builder: (context) {
    return AlertDialog(
    title: Text('提示'),
    content: Text('确定要取消吗'),
    actions: <Widget>[
    FlatButton(child: Text('取消'), onPressed: () {Navigator.pop(context, '222');},),
    FlatButton(child: Text('确定'), onPressed: () {Navigator.pop(context, '222');},),
    ],
    );
    }
    );
    },
    ),
    RaisedButton(
    child: Text('弹出选择卡'),
    onPressed: () {
    showDialog(
    context: context,
    builder: (context) {
    return SimpleDialog(
    title: Text('选择卡'),
    children: <Widget>[
    SimpleDialogOption(child: Text('A'), onPressed: () { Navigator.pop(context);},),
    SimpleDialogOption(child: Text('B'), onPressed: () { Navigator.pop(context);},),
    SimpleDialogOption(child: Text('C'), onPressed: () { Navigator.pop(context);},),
    ],
    );
    }
    );
    },
    ),
    RaisedButton(
    child: Text('弹出自定义'),
    onPressed: () {
    showDialog(
    context: context,
    builder: (context) {
    return MyDialog(title:"关于我们", content:"关于我们");
    }
    );
    },
    )
    ],
    )
    );
    }
    }




    // 自定义dialog
    import 'dart:async';

    import 'package:flutter/material.dart';
    //MyDialog(title:"关于我们", content:"关于我们"); 引入文件 然后调用方法

    class MyDialog extends Dialog {
    String title;
    String content;

    MyDialog({this.title="",this.content=""});

    _showTimer(context){
    var timer;
    timer = Timer.periodic(
    Duration(milliseconds: 3000), (t) {

    print('关闭');
    Navigator.pop(context);
    t.cancel(); //取消定时器 timer.cancel();
    });
    }

    @override
    Widget build(BuildContext context) {

    _showTimer(context);

    // TODO: implement build
    return Material(
    type: MaterialType.transparency,
    child: Center(
    child: Container(
    height: 300,
    300,
    color: Colors.white,
    child: Column(
    children: <Widget>[
    Padding(
    padding: EdgeInsets.all(10),
    child: Stack(
    children: <Widget>[
    Align(
    alignment: Alignment.center,
    child: Text("${this.title}"),
    ),
    Align(
    alignment: Alignment.centerRight,
    child: InkWell(
    child: Icon(Icons.close),
    onTap: (){
    Navigator.pop(context);
    },
    ),
    )
    ],
    ),
    ),
    Divider(),
    Container(
    padding: EdgeInsets.all(10),
    double.infinity,
    child: Text("${this.content}",textAlign: TextAlign.left),
    )
    ],
    ),

    )),
    );
    }
    }
  • 相关阅读:
    editplus 支持lua语言语法高亮显示
    云服务器使用: 域名备案
    2-使用git管理一个单片机程序
    1-git的安装和基本使用
    编译lua固件NodeMcu 8266
    linux 安装Apache服务器
    2-STM32物联网开发WIFI(ESP8266)+GPRS(Air202)系统方案安全篇(监听Wi-Fi和APP的数据)
    Spring源码学习之:ClassLoader学习(3)
    Spring源码学习之:ClassLoader学习(2)
    Spring源码学习之:ClassLoader学习(1)
  • 原文地址:https://www.cnblogs.com/zhaofeis/p/12359216.html
Copyright © 2011-2022 走看看