Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/background.png"),
fit: BoxFit.fill)),
child: ...
);
Last active
October 26, 2020 09:54
-
-
Save SongFuZhen/ee4a80d6b1c151dc394d20a315d4d2cf to your computer and use it in GitHub Desktop.
保证
Router
中的home
已经设置了
使用WillPopScope
监听返回按键
在Widget
中使用如下
import 'package:flutter/services.dart'; // 用来退出app
import 'dart:io'; // 用来退出app
...
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async {
// 点击返回键的操作
if (lastPopTime == null ||
DateTime.now().difference(lastPopTime) > Duration(seconds: 2)) {
lastPopTime = DateTime.now();
Toast.show("再按一次退出", context, duration: Toast.LENGTH_SHORT);
return false;
} else {
// 退出app
lastPopTime = DateTime.now();
await SystemChannels.platform.invokeMethod('SystemNavigator.pop');
exit(0);
return true;
}
},
child: yourContent )});
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment