当前位置:网站首页>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),
)
],
),
)),
);
}
}
边栏推荐
- 2.0 detailed explanation of ROS and Px4 communication
- Multipartfile and file interoperation tool classes
- 1.6 Px4 initialization calibration
- How to download web photos
- What if ROS lacks a package
- 2.2、ROS+PX4仿真多点巡航飞行----正方形
- 2021-02-27MATLAB的图像处理
- Negative number +0+ positive number
- 【云原生 | Kubernetes篇】Ingress案例实战
- OCR文字识别经典论文详解
猜你喜欢
![[ROS] review of 2021 ROS Summer School](/img/1c/588d29b60071628c7c9fdce17e8b84.jpg)
[ROS] review of 2021 ROS Summer School

flutter 状态管理

Garbled code when the command parameter contains% in VisualStudio debugging

LeetCode 1609 Even Odd Tree (bfs)

detectron2训练自己的数据集和转coco格式

神经网络极简史,神经网络知识点整理

On permutation and combination in probability and statistics

2.0 detailed explanation of ROS and Px4 communication

【错误记录】Android 应用安全检测漏洞修复 ( StrandHogg 漏洞 | 设置 Activity 组件 android:taskAffinity=““ )

Leetcode 652 find duplicate subtrees (recommended by DFS)
随机推荐
Leetcode 1574 shortest subarray to be removed to make array sorted
晚餐阿帮的手艺
Leetcode 652 find duplicate subtrees (recommended by DFS)
MATLAB数组其他常见操作笔记
[VBA Script] extract the information and pending status of all annotations in the word document
2.2、ROS+PX4仿真多点巡航飞行----正方形
Px4 from abandonment to mastery (twenty four): customized model
2021-02-03美赛前MATLAB的学习笔记(灰色预测、线性规划)
MultipartFile和File互转工具类
[leetcode] a group of K flipped linked lists
Detailed explanation of classic papers on OCR character recognition
逻辑漏洞 / 业务漏洞
[leetcode] delete duplicate Element II in the sorting linked list
threejs:如何获得几何体的boundingBox?
MeterSphere教程:接口返回结果为空时如何进行断言
1.6、 PX4初始化校准
[ongoing update...] 2021 National Electronic Design Competition for college students (III) interpretation of the anonymous four axis space developer flight control system design
Exj shaped children will be satisfied with mbtxe due to disconnection
“看似抢票实际抢钱”,别被花式抢票产品一再忽悠
2021-2-26 compilation of programming language knowledge points