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. shell脚本实战

    想写个脚本,发现都忘了,蛋疼,一边回忆一边查一边写,总算完成了,贴在下面: #!/bin/bash #Program: # This program can help you quickly rede ...

  2. 代码报错--------EOFError: Compressed file ended before the end-of-stream marker was reached

    背景:运行LeNet识别CIFAR-10的图像的代码时,报错: EOFError: Compressed file ended before the end-of-stream marker was ...

  3. host文件介绍

    默认位置为%SystemRoot%\system32\drivers\etc\,但也可以改变. 动态目录由注册表键\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSe ...

  4. Java事务(转载)

    Java事务的类型有三种:JDBC事务.JTA(Java Transaction API)事务.容器事务. 1.JDBC事务 JDBC 事务是用 Connection 对象控制的.JDBC Conne ...

  5. maven项目编译报错:Type Dynamic Web Module 3.0 requires Java 1.6 or newer.

    在maven的pom.xml文件中增加: <build>   <plugins>     <plugin>         <groupId>org.a ...

  6. MySQL user表初始化

    默认安装的MySQL数据库,无法远程连接. 登录MySQL之后,运行 SELECT user,host from mysql.user; 如果只有一条记录,说明是这个原因. 将下面的脚本保存成user ...

  7. hiho #1038 : 01背包 (dp)

    #1038 : 01背包 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 且说上一周的故事里,小Hi和小Ho费劲心思终于拿到了茫茫多的奖券!而现在,终于到了小Ho领取奖励 ...

  8. 前端js之JQuery

    目录 jQuery介绍 jQuery的优势 jQuery内容 jQuery对象 jQuery基础语法结构 jQuery 使用注意事项 查找标签 基本选择器 层级选择器 基本选择器 属性选择器 表单筛选 ...

  9. buuctf@helloword

  10. [Flask]celery异步任务队列的使用

    Celery异步任务队列 目录结构树: 配置文件config.py: # 设置中间人地址 broker_url = 'redis://127.0.0.1:6379/1' 主main.py: impor ...