当前位置:网站首页>(shuttle) navigation return interception: willpopscope
(shuttle) navigation return interception: willpopscope
2022-07-06 22:56:00 【Xiaobai is more than that】
1. Calculate the time difference between two dates
DateTime.now().difference(_lastPressedAt!)
// Use difference Method , You can get the difference of all time units
among ,DateTime
Of difference Method
Back to a Duration object
.Duration
It's used to show time span ( Difference value )
Class .
Reference article :
Flutter Calculate the time difference between two dates
Xiaobai is more than that :(Dart) Usage supplement
2. Navigation returns to intercept : WillPopScope
DateTime? _lastPressedAt; // Last click time
@override
Widget build(BuildContext context) {
return WillPopScope(
child: Scaffold(
body: Container(
alignment: Alignment.center,
child: Text("2 Press the return key twice in a row within seconds to exit "),
),
),
onWillPop: () async {
if (_lastPressedAt == null || DateTime.now().difference(_lastPressedAt!) > Duration(seconds: 2)) {
// The interval between two clicks is more than 2 Second is the second
_lastPressedAt = DateTime.now();
Fluttertoast.showToast(
msg: ' Press again to exit !',
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 2,
backgroundColor: Colors.black87,
textColor: Colors.white,
);
return false;// Current route does not stack ( Will not return )
}
return true;// The current route exits the stack
},
);
}
Reference article :
Navigation returns to intercept (WillPopScope)
边栏推荐
猜你喜欢
MySQL ---- first acquaintance with MySQL
European Bioinformatics Institute 2021 highlights report released: nearly 1million proteins have been predicted by alphafold
【Unity】升级版·Excel数据解析,自动创建对应C#类,自动创建ScriptableObject生成类,自动序列化Asset文件
【编译原理】做了一半的LR(0)分析器
自定义 swap 函数
[compilation principle] LR (0) analyzer half done
MySQL中正则表达式(REGEXP)使用详解
浅谈网络安全之文件上传
Export MySQL table data in pure mode
监控界的最强王者,没有之一!
随机推荐
Precise drag and drop within a contentable
2014阿里巴巴web前实习生项目分析(1)
dockermysql修改root账号密码并赋予权限
Improving Multimodal Accuracy Through Modality Pre-training and Attention
Leetcode: interview question 17.24 Maximum cumulative sum of submatrix (to be studied)
「小程序容器技术」,是噱头还是新风口?
DockerMySQL无法被宿主机访问的问题解决
树的先序中序后序遍历
如何实现文字动画效果
docker中mysql开启日志的实现步骤
View
专为决策树打造,新加坡国立大学&清华大学联合提出快速安全的联邦学习新系统
OpenNMS separation database
Hard core observation 545 50 years ago, Apollo 15 made a feather landing experiment on the moon
[step on pit collection] attempting to deserialize object on CUDA device+buff/cache occupy too much +pad_ sequence
European Bioinformatics Institute 2021 highlights report released: nearly 1million proteins have been predicted by alphafold
DR-Net: dual-rotation network with feature map enhancement for medical image segmentation
关于声子和热输运计算中BORN电荷和non-analytic修正的问题
Windows Auzre 微软的云计算产品的后台操作界面
MySQL ---- first acquaintance with MySQL