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. Robot Framework--接口测试中常见的四种POST方式

    写接口测试用例时,遇到以json格式提交数据时,报错,Request如下图: Response如下图: 改成form格式提交,可以正常运行,如下图: 代码如下: ------------------- ...

  2. archlinux 使用 postgresql

    一.安装与初始化 1.初始化数据目录 默认安装后已创建 postgres 系统用户 切换到 postgres 用户 $ sudo -iu postgres # Or su - postgres for ...

  3. Selenium常用API的使用java语言之6-WebDriver常用方法

    前面我们已经学习了定位元素, 定位只是第一步, 定位之后需要对这个元素进行操作, 或单击(按钮) 或 输入(输入框) , 下面就来认识这些最常用的方法. 1.WebDriver 常用方法 下面先来认识 ...

  4. VS2010 insert Oracle数据库

    背景:批量插入上万条数据到Oracle数据库的一张表里. 工具:VS2010. 因为是访问远程数据库,所以需要先装一个oracle client. 使用oracle客户端的方式访问数据库,需要添加对其 ...

  5. LeetCode 273. Integer to English Words

    原题链接在这里:https://leetcode.com/problems/integer-to-english-words/description/ 题目: Convert a non-negati ...

  6. sql server replace 的使用方法

    Sql Server REPLACE函数的使用   REPLACE用第三个表达式替换第一个字符串表达式中出现的所有第二个给定字符串表达式. 语法REPLACE ( ''string_replace1' ...

  7. 小象和老鼠 DP

    小象和老鼠 DP \(N*M\)的网格图,格子\((i,j)\)有\(A_{i,j}\)个老鼠,问小象从左上角\((1,1)\)走到右下角\((N,M)\)看到的最少老鼠.小象可以看见老鼠,当且仅当老 ...

  8. js自动访问数据库

    js自动访问数据库 maven依赖 <dependencies> <dependency> <groupId>junit</groupId> <a ...

  9. 第五章、web服务器

    一.web服务器 Web服务器就是整个万维网的骨干,广义上来说Web服务器既可以用来表示Web服务器的软件,也可以用来表示提供Web页面的特定设备和计算机.我们在网络上获取的所以资源,都需要有服务器来 ...

  10. ElasticSearch java客户端更新时出现的错误:NoNodeAvailableException[None of the configured nodes are available

    下午尝试 用ElasticSearch  的java客户端去做数据检索工作,测试了一下批量更新,代码如下: public static void bulkUpdateGoods(List<Goo ...