I want to back programmatically without press back button , ("trigger back button functionality without pressing it ") ?
Asked
Active
Viewed 534 times
2
-
`Navigator.pop(context)` ? – esentis Aug 29 '21 at 11:12
-
I don't use stack of navigation , so If trigger this function in the root page the app will crashes because the back button functionality here is to close the app . – Omar Abdelazeem Aug 29 '21 at 11:15
-
What kind of navigation are you using then ? Some code would help. – esentis Aug 29 '21 at 11:16
-
I think this will help you to figure out [programmatically exit the app](https://stackoverflow.com/a/57534684/4954386) – Zah_ARin Aug 29 '21 at 11:24
1 Answers
1
I think you can use WillPopScope class for this case
bool shouldPop = true;
@override
Widget build(BuildContext context) {
return WillPopScope (
onWillPop: () async {
return shouldPop;
},
child: const Text('WillPopScope sample'),
);
}
Hope this helps. You can read more in the official documentation https://api.flutter.dev/flutter/widgets/WillPopScope-class.html

Aditya
- 740
- 1
- 5
- 11