当前位置:网站首页>Dialog alertdialog, simpledialog, showmodalbottomsheet, showtoast shutter custom dialog
Dialog alertdialog, simpledialog, showmodalbottomsheet, showtoast shutter custom dialog
2022-06-11 01:51:00 【weixin_ thirty-eight million one hundred and seven thousand fou】
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:untitled/pages/itying/DialogPage.dart';
class DialogDemo extends StatefulWidget {
const DialogDemo({Key? key}) : super(key: key);
@override
State<DialogDemo> createState() => _DialogDemoState();
}
class _DialogDemoState extends State<DialogDemo> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar:AppBar(
title: Text("Dialog"),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: _alertDialog,
child: Text('alert pop-up -AlertDialog '),
),
SizedBox(height: 20),
ElevatedButton(
child: Text('select pop-up -SimpleDialog'),
onPressed: _simpleDialog,
),
SizedBox(height: 20),
ElevatedButton(
child: Text('ActionSheet Bottom pop-up -showModalBottomSheet'),
onPressed: _modelBottomSheet,
),
SizedBox(height: 20),
ElevatedButton(
child: Text('toast-fluttertoast Third party Library '),
onPressed: _toast,
),
ElevatedButton(
child: Text(' Customize Dialog'),
onPressed: (){
showDialog(
context: context,
builder: (context){
return MyDialog(
title: " About us ",
content: " I am content. ",
);
});
},
),
],
),
),
);
}
_alertDialog() async{
var result = await showDialog(
context: context,
builder: (BuildContext context){
return AlertDialog(
title: Text(" Prompt information !"),
content: Text(" Are you sure you want to delete ?"),
actions: [
TextButton(
child: Text(" Cancel "),
onPressed: (){
print(" Cancel ");
Navigator.pop(context,'Cancle');
},
),
TextButton(
child: Text(" determine "),
onPressed: (){
print(" determine ");
Navigator.pop(context,"Ok");
},
)
],
);
}
);
print(result);
}
_simpleDialog() async{
var result = await showDialog(
barrierDismissible:false, // Indicates whether the pop-up box disappears when clicking on the gray background
context: context,
builder: (BuildContext context){
return SimpleDialog(
title: Text(" Select content "),
children: [
SimpleDialogOption(
child: Text("Option A"),
onPressed: (){
print("Option A");
Navigator.pop(context,"A");
},
),
Divider(),
SimpleDialogOption(
child: Text("Option B"),
onPressed: (){
print("Option B");
Navigator.pop(context,"B");
},
),
Divider(),
SimpleDialogOption(
child: Text("Option C"),
onPressed: (){
print("Option C");
Navigator.pop(context,"C");
},
),
Divider(),
],
);
});
print(result);
}
_modelBottomSheet() async{
var result=await showModalBottomSheet(
context:context,
builder: (context){
return Container(
height: 220,
child: Column(
children: <Widget>[
ListTile(
title: Text(" Share A"),
onTap: (){
Navigator.pop(context," Share A");
},
),
Divider(),
ListTile(
title: Text(" Share B"),
onTap: (){
Navigator.pop(context," Share B");
},
),
Divider(),
ListTile(
title: Text(" Share C"),
onTap: (){
Navigator.pop(context," Share C");
},
)
],
),
);
}
);
print(result);
}
_toast(){
Fluttertoast.showToast(
msg: " Prompt information ",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 1,
backgroundColor: Colors.black,
textColor: Colors.white,
fontSize: 16.0
);
}
}Flutter Customize Dialog
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: 3000), (t) {
print(' close ');
Navigator.pop(context);
timer.cancel(); // Cancel timer t.cancel();
});
}
@override
Widget build(BuildContext context) {
_showTimer(context);
// TODO: implement build
return Material(
type: MaterialType.transparency,
child: Center(
child: Container(
height: 300,
width: 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),
width: double.infinity,
child: Text("${this.content}",textAlign: TextAlign.left),
)
],
),
)),
);
}
}
边栏推荐
- Matlab array other common operation notes
- 从解读 BDC 自动生成的代码谈起,讲解 SAPGUI 的程序组成部分试读版
- Tencent Cloud Database tdsql - Dajia comments | The Past, Present and Future of basic software
- 腾讯云数据库TDSQL-大咖论道 | 基础软件的过去、现在、未来
- Makefile:1860: recipe for target ‘cmake_ check_ build_ system‘ failed make: *** [cmake_check_build_syst
- MeterSphere教程:接口返回结果为空时如何进行断言
- Leetcode linked list queue stack problem
- 2022.6.6-----leetcode.732
- 薪的测试开发程序员们,你为何要走?和产品相互残杀到天昏地暗......
- 關於概率統計中的排列組合
猜你喜欢

2021-02-27image processing of MATLAB

Linux安装mysql数据库详解

Px4 from abandonment to mastery (twenty four): customized model

QGC地面站使用教程

从解读 BDC 自动生成的代码谈起,讲解 SAPGUI 的程序组成部分试读版
![[interpretation of the paper] sort out the papers on the vision based autonomous landing platform of UAV](/img/fe/04d95b8d983f491b8e8d4bae7d07ca.jpg)
[interpretation of the paper] sort out the papers on the vision based autonomous landing platform of UAV
![[VBA Script] extract the information and pending status of all annotations in the word document](/img/dc/0db51d092cde019cef4113796e4882.png)
[VBA Script] extract the information and pending status of all annotations in the word document

视频压缩数据集TVD

2.2. Ros+px4 simulation multi-point cruise flight - Square

關於概率統計中的排列組合
随机推荐
Leetcode 698 partition to K equal sum subsets (DFS pruning)
懒汉式单例模式
QGC ground station tutorial
1.7 calibration of Px4 remote controller
PX4从放弃到精通(二十四):自定义机型
视频压缩数据集TVD
2021-7-18 ROS notes XML language related
【云原生 | Kubernetes篇】Ingress案例实战
[ROS introduction] cmakelist Txt and packages XML interpretation
[mavros] mavros startup Guide
[ROS] review of 2021 ROS Summer School
[leetcode] intersecting linked list
From "0" to "tens of millions" concurrency, 14 technological innovations of Alibaba distributed architecture
[leetcode] delete duplicate Element II in the sorting linked list
小包子关于分红的思考
1.7、PX4遥控器校准
薪的测试开发程序员们,你为何要走?和产品相互残杀到天昏地暗......
Leetcode 2054 two best non overlapping events
Leetcode 665 non decreasing array (greedy)
On permutation and Combination in Probabilistic Statistics