[英]Flutter AlertDialog Navigator.pop(context) returning a black screen
[英]Navigator.pop(context) show black screen while finish the last Activity in stack in Flutter
我對此進行了很多搜索,但尚未找到正確的解決方案。 我想知道Flutter等同於finish()(在Java for Android中)
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () {
if (counter == 1) {
// **What should I write here so that my current activity is destroyed with showing the Toast message.**
}
Fluttertoast.showToast(
msg: "Press again for exit!",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
);
counter++;
Timer(Duration(seconds: 2), () {
counter = 0;
});
print(counter);
},
child: new Scaffold(
....................
);
);
}
我已經找到解決方案。 絕對可以!
@override
Widget build(BuildContext context) {
return new WillPopScope(
onWillPop: () {
if (counter == 1) {
return Future.value(true);
}
Fluttertoast.showToast(
msg: "Press again for exit!",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
);
counter++;
Timer(Duration(seconds: 2), () {
counter = 0;
});
return Future.value(false);
},
child: new Scaffold(
..................
));
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.