flutter Dialog

import 'dart:math';

import 'package:flutter/material.dart';
import 'test.dart';
import 'package:flutter/cupertino.dart'; class HomePage extends StatelessWidget {
var selectedIndex = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Dialog'),
),
body: Builder(builder: (BuildContext context) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
RaisedButton(
child: Text('SimpleDialog'),
onPressed: () {
_showSimpleDialog(context);
},
),
RaisedButton(
child: Text('AlertDialog'),
onPressed: () {
_showAlertDialog(context);
},
),
RaisedButton(
child: Text('CupertinoAlertDialog'),
onPressed: () {
_showCupertinoAlertDialog(context);
},
),
RaisedButton(
child: Text('CustomDialog'),
onPressed: () {
_showCustomDialog(context);
},
),
RaisedButton(
child: Text('bottomSheet'),
onPressed: () {
_showBottomView(context);
},
),
RaisedButton(
child: Text('bottomSelectSheet'),
onPressed: () {
_showSelectionDialog(context);
},
),
],
),
);
}));
} void _showBottomView(BuildContext context) {
var datas = List.generate(20, (index) {
return 'datas$index';
});
showModalBottomSheet(
context: context,
isScrollControlled: false,
builder: (ctx) {
return Container(
height: 200,
color: Colors.white,
child: Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
FlatButton(
child: Text('取消'),
onPressed: () {
Navigator.pop(context);
},
),
FlatButton(
child: Text('确定'),
splashColor: Colors.grey,
highlightColor: Colors.white,
onPressed: () {
Navigator.pop(context);
print('selectedIndex:$selectedIndex' +
'data:${datas[selectedIndex]}');
},
),
],
),
Expanded(
child: CupertinoPicker(
children: datas.map((item) {
return Text(item);
}).toList(),
onSelectedItemChanged: (index) {
print('$index');
selectedIndex = index;
},
itemExtent: 36,
),
)
],
),
);
},
);
} void _showSimpleDialog(BuildContext context) {
showDialog(
context: context,
// barrierDismissible: false,
builder: (ctx) {
return SimpleDialog(
// title: Text('SimpleDialog',textAlign: TextAlign.center,),
// titlePadding: EdgeInsets.all(10),
backgroundColor: Colors.amber,
elevation: 5,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(6),
),
),
contentPadding: EdgeInsets.all(0),
children: <Widget>[
GestureDetector(
child: Image.asset(
'assets/123.jpg',
fit: BoxFit.cover,
// height: 400,
// width: 400,
),
onTap: () {
//先关闭弹窗
Navigator.pop(context);
//跳转到下一页
Navigator.push(
context,
MaterialPageRoute(builder: (context) => TestPage()),
);
},
)
// ListTile(
// title: Center(
// child: Text("Item_1"),
// ),
// ),
// ListTile(
// title: Center(
// child: Text("Item_2"),
// ),
// ),
// ListTile(
// title: Center(
// child: Text("Item_3"),
// ),
// ),
// ListTile(
// title: Center(
// child: Text("Close"),
// ),
// onTap: () {
// Navigator.pop(context);
// },
// ),
],
);
},
);
} void _showAlertDialog(BuildContext context) {
showDialog(
context: context,
barrierDismissible: true,
builder: (ctx) {
return AlertDialog(
title: Text(
'data',
textAlign: TextAlign.center,
),
content: Text(
'datadatadatadatadatasdadadatadatadatadatadatadatadatadatadatadatadatadata'),
elevation: 5,
actions: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
FlatButton(
child: Text('确定'),
onPressed: () {},
),
FlatButton(
child: Text('取消'),
onPressed: () {
Navigator.pop(context);
},
),
],
),
],
);
},
);
} void _showCupertinoAlertDialog(BuildContext context) {
showDialog(
context: context,
barrierDismissible: true,
builder: (ctx) {
return CupertinoAlertDialog(
title: Text(
'data',
textAlign: TextAlign.center,
),
content: Text(
'datadatadatadatadatasdadadatadatadatadatadatadatadatadatadatadatadatadata'),
// elevation: 5,
actions: <Widget>[
// Row(
// mainAxisAlignment: MainAxisAlignment.spaceEvenly,
// children: <Widget>[
FlatButton(
child: Text('确定'),
onPressed: () {},
),
FlatButton(
child: Text('取消'),
onPressed: () {
Navigator.pop(context);
},
// ),
// ],
)
],
);
},
);
} void _showCustomDialog(BuildContext context) {
showDialog(
context: context,
barrierDismissible: true,
builder: (ctx) {
return CustomDialog();
},
);
} void _showSelectionDialog(BuildContext context) {
showModalBottomSheet(
context: context,
isScrollControlled: false,
builder: (ctx) {
return Container(
color: Colors.grey,
height: 130,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
// mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
GestureDetector(
child: _itemCreat(context, '相机'),
onTap: (){
print('选中相机');
},
),
GestureDetector(
child: _itemCreat(context, '相册'),
onTap: (){
print('选中相册');
},
),
GestureDetector(
child: Padding(
padding: EdgeInsets.only(top: 10),
child: _itemCreat(context, '取消'),
),
onTap: (){
Navigator.pop(context);
},
)
],
),
);
},
);
} Widget _itemCreat(BuildContext context, String title) {
return Container(
color: Colors.white,
height: 40,
width: MediaQuery.of(context).size.width,
child: Center(
child: Text(
title,
style: TextStyle(fontSize: 16, color: Colors.black),
textAlign: TextAlign.center,
),
),
);
}
} class CustomDialog extends Dialog {
CustomDialog({Key key}) : super(key: key); @override
Widget build(BuildContext context) {
return Center(
child: Container(
color: Colors.white,
height: 365,
padding: EdgeInsets.all(10),
child: Column(
children: <Widget>[
Image.asset(
'assets/123.jpg',
fit: BoxFit.cover,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
FlatButton(
onPressed: () {
Navigator.pop(context);
},
child: Text('确定'),
),
FlatButton(
onPressed: () {
Navigator.pop(context);
},
child: Text('取消'),
)
],
)
],
),
),
);
}
}

flutter dialog的更多相关文章

  1. flutter dialog异常Another exception was thrown: No MaterialLocalizations found

    flutter dialog异常Another exception was thrown: No MaterialLocalizations found import 'package:flutter ...

  2. 29 Flutter Dialog AlertDialog 、SimpleDialog、showModalBottomSheet、showToast

    pubspec.yaml fluttertoast: ^ Dialog.dart import 'package:flutter/material.dart'; import 'package:flu ...

  3. flutter dialog异常Another exception was thrown: Navigator operation requested with a context that does not include a Navigator

    我在使用flutter里的对话框控件的时候遇到了一个奇怪的错误 Another exception was thrown: Navigator operation requested with a c ...

  4. 这一次,解决Flutter Dialog的各种痛点!

    前言 Q:你一生中闻过最臭的东西,是什么? A:我那早已腐烂的梦. 兄弟萌!!!我又来了! 这次,我能自信的对大家说:我终于给大家带了一个,能真正帮助大家解决诸多坑比场景的pub包! 将之前的flut ...

  5. flutter Dialog里ListView的问题

    showDialog( context: context, builder: (ctx) { return // Dialog( // child: Container( // padding: Ed ...

  6. 一种更优雅的Flutter Dialog解决方案

    前言 系统自带的Dialog实际上就是Push了一个新页面,这样存在很多好处,但是也存在一些很难解决的问题 必须传BuildContext loading弹窗一般都封装在网络框架中,多传个contex ...

  7. Flutter Dialog 屏蔽返回键

    使用 WillPopScope + Future.value(false); 屏蔽返回键.代码如下: showDialog<Null>( context: context, // Buil ...

  8. Flutter GetX使用---简洁的魅力!

    前言 使用Bloc的时候,有一个让我至今为止十分在意的问题,无法真正的跨页面交互!在反复的查阅官方文档后,使用一个全局Bloc的方式,实现了"伪"跨页面交互,详细可查看:flutt ...

  9. Flutter 改善套娃地狱问题(仿喜马拉雅PC页面举例)

    前言 这篇文章是我一直以来很想写的一篇文章,终于下定决心动笔了. 写Flutter的小伙伴可能都感受到了:掘金的一些热门的Flutter文章下,知乎的一些Flutter的话题下或者一些论坛里面,喷Fl ...

随机推荐

  1. 【有钱的大佬看过来】Java开发学习大纲

    Java开发学习大纲文档V7.0 有钱的大佬可以买下这个版权,全网最完整最详细了,没钱的大佬可以按照自己的方式去整理.有需要的私聊作者QQ:253173641 来源于-幸福的沉淀:https://ww ...

  2. 004-linux下配置rsyslog日志收集服务器案例 rsyslog+loganalyzer日志服务器,无法添加报表模板解决

    centos6系统 client1:192.168.1.33 centos7系统 client2:192.168.1.44 centos7系统 master:192.168.1.55 配置服务端mas ...

  3. 如何在 Ubuntu 上安装 pip

    1.为 Python 2 安装 pip 首先,确保已经安装了 Python 2. 在 Ubuntu 上,可以使用以下命令进行验证 python2 --version 如果没有错误并且显示了 Pytho ...

  4. mysql 存储过程(二)

    存储过程(Stored Procedure): 一组可编程的函数,是为了完成特定功能的SQL语句集,经编译创建并保存在数据库中,用户可通过指定存储过程的名字并给定参数(需要时)来调用执行. 优点(为什 ...

  5. 介绍知道的http返回的状态码

    100    Continue    继续.客户端应继续其请求 101    Switching Protocols    切换协议.服务器根据客户端的请求切换协议.只能切换到更高级的协议,例如,切换 ...

  6. 第二章 Vue快速入门-- 18 v-for中key的使用注意事项

    注意:如果属性和方法还没定义直接使用的话,就会报   xxx is not defined 导致界面不能正常显示.我看视频教程里老师的可以直接使用,而且界面正常显示,可能是vue版本不同吗?还不清楚 ...

  7. DevExpress ASP.NET Core v19.1版本亮点:Visual Studio集成

    行业领先的.NET界面控件DevExpress 发布了v19.1版本,本文将以系列文章的方式为大家介绍DevExpress ASP.NET Core Controls v19.1中新增的一些控件及增强 ...

  8. 理解 Cookie、Session、Token

    发展史 Cookie Session Token Token的起源 基于服务器的验证 基于服务器验证方式暴露的一些问题 基于Token的验证原理 Tokens的优势 发展史 1.很久很久以前,Web ...

  9. base64 转 Image

    /// <summary> /// base64 转 Image /// </summary> /// <param name="base64"> ...

  10. hivesql之str_to_map函数

    str_to_map(字符串参数, 分隔符1, 分隔符2) 使用两个分隔符将文本拆分为键值对. 分隔符1将文本分成K-V对,分隔符2分割每个K-V对.对于分隔符1默认分隔符是 ',',对于分隔符2默认 ...