MyDialog.dart

import 'dart:async';

import 'package:flutter/material.dart';

class MyDialog extends Dialog {
String title;
String content; MyDialog({this.title="",this.content=""}); _showTimer(context){
var timer;
timer=Timer.periodic(
Duration(milliseconds:),(t){
print("关闭");
Navigator.pop(context);
t.cancel();//取消定时器 timer.cancle();
}
);
} @override
Widget build(BuildContext context) {
_showTimer(context);
return Material(
type: MaterialType.transparency,
child: Center(
child: Container(
height: ,
width: ,
color: Colors.white,
child: Column(
children: <Widget>[
Padding(
padding: EdgeInsets.all(),
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(),
width: double.infinity,
child: Text("${this.content}",textAlign: TextAlign.left),
)
],
),
),
),
);
}
}

Dialog.dart

import 'package:flutter/material.dart';
import 'package:flutter_example/components/MyDialog.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: ,
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: ,
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: ),
RaisedButton(
child: Text('select弹出框-SimpleDialog'),
onPressed: _simpleDialog,
),
SizedBox(height: ),
RaisedButton(
child: Text('ActionSheet弹出框-showModalBottomSheet'),
onPressed: _modelBottomSheet,
),
SizedBox(height: ),
RaisedButton(
child: Text('toast-fluttertoast第三方库'),
onPressed: _toast,
),
SizedBox(height: ),
RaisedButton(
child: Text('显示自定义Dialog'),
onPressed:(){
showDialog(
context: context,
builder: (context){
return MyDialog(title:'关于我们',content:'z这是内容部分');
}
);
},
),
],
),
),
);
}
}

30 Flutter自定义Dialog的更多相关文章

  1. Flutter - 自定义Dialog弹窗

    ------------恢复内容开始------------ Flutter - 自定义Dialog弹窗 应用场景:app系统版本升级弹窗,系统退出登录弹窗,首页广告弹窗,消息中心弹窗,删除文件弹窗等 ...

  2. Flutter学习笔记(41)--自定义Dialog实现版本更新弹窗

    如需转载,请注明出处:Flutter学习笔记(41)--自定义Dialog实现版本更新弹窗 功能点: 1.更新弹窗UI 2.强更与非强更且别控制 3.屏蔽物理返回键(因为强更的时候点击返回键,弹窗会消 ...

  3. AlertDialog 、SimpleDialog、 showModalBottomSheet、showToast 自定义 Dialog

    // AlertDialog .SimpleDialog.showModalBottomSheet.showToast // 使用showToast安装插件 https://pub.dev/packa ...

  4. 自定义Dialog宽度占满屏幕

    一.自定义Dialog继承Dialog public class MyDialog extends Dialog { 二.为Dialog设置样式 在style中建立新样式继承 @android:sty ...

  5. Android中制作自定义dialog对话框的实例

    http://www.jb51.net/article/83319.htm   这篇文章主要介绍了Android中制作自定义dialog对话框的实例分享,安卓自带的Dialog显然不够用,因而我们要继 ...

  6. 非自定义和自定义Dialog的介绍!!!

    一.非自定义Dialog的几种形式介绍 转自:http://www.kwstu.com/ArticleView/kwstu_20139682354515 前言 对话框对于应用也是必不可少的一个组件,在 ...

  7. Android开发之自定义Dialog简单实现

    本文着重研究了自定义对话框,通过一下步骤即可清晰的理解原理,通过更改界面设置和style类型,可以应用在各种各样适合自己的App中. 首先来看一下效果图: 首先是activity的界面 点击了上述图片 ...

  8. Android—自定义Dialog

    在 Android 日常的开发中,Dialog 使用是比较广泛的.无论是提示一个提示语,还是确认信息,还是有一定交互的(弹出验证码,输入账号密码登录等等)对话框. 而我们去看一下原生的对话框,虽然随着 ...

  9. Android自定义Dialog(美化界面)

    前言:在做项目的时候,发现dialog界面太丑陋,从csdn上下载了一份自定义dialog的源码,在他的基础上对界面进行美化...有需要的朋友可以直接拿走 效果图如下: 主要代码: /** * 自定义 ...

随机推荐

  1. {RuntimeError} An attempt has been made to start a new process before the current process has finished its bootstrapping phase.This probably means that you are not using fork to start your child...

    加载数据时出现报错: RuntimeError:         An attempt has been made to start a new process before the        c ...

  2. Ansible批量自动化管理工具

    一,工具与环境介绍 1.1 ansible简介 批量管理服务器的工具 无需部署agent,通过ssh进行管理 流行的自动化运维工具:https://github.com/ansible/ansible ...

  3. Maven创建本地仓库

    1:创建仓库目录 在D盘Program Files目录下创建repository目录 2:修改settings.xml ​ ​ D:\ProgramFiles\repository  是我们创建的本地 ...

  4. WPF 反编译后错误处理

    1. 首先,手动创建一个WPF工程(WpfApplicationReflectorDemo) 2. 把生成的WpfApplicationReflectorDemo.exe 拖到ILSpy里 3.点击 ...

  5. Robot Framework--连接Mysql数据库

    1.安装Database-Library 输入命令:pip install robotframework_databaselibrary 2.添加Database的Library 3.实例 *** T ...

  6. STM32的指令周期

    在keil中编程时,写了一行代码,然后就想知道,执行这句C代码需要多长时间. 时钟周期在这就不解释了,频率的倒数. 指令周期,个人理解就是cpu执行一条汇编指令所需要的时间. 我们知道cm3使用的三级 ...

  7. oracle数据库中 impdb/expdb 详解

    创建逻辑目录,该命令不会在操作系统创建真正的目录,最好以system等管理员创建.create directory dpdata as 'd:\test\dump'; 二.查看管理理员目录(同时查看操 ...

  8. Vue获取后端数据 渲染页面后跳转

    主页面 <template> <div> <ul v-for="item in courseList"> <router-link :to ...

  9. python AES对称加密

    1.首先需要安装第三方库 pip install pycryptodome 2.实例代码,亲测可用 # coding:utf-8 import base64 from Crypto.Cipher im ...

  10. [Javascript] Construct a Regex to Match Twitter Mentions with Regexr

    regexr is a powerful tool for debugging existing regexes and creating new ones. In this lesson, we'l ...