is it possible to detect that user clicked on the button back of the phone as this image and change it functionality for example if the user clicked on that button i want to take him to the page Data() not to the previous page . enter image description here
Asked
Active
Viewed 434 times
1
-
See this answer https://stackoverflow.com/a/45918186/11445944 – Miftakhul Arzak Jul 04 '22 at 10:00
-
Does this answer your question? [How to deactivate or override the Android "BACK" button, in Flutter?](https://stackoverflow.com/questions/45916658/how-to-deactivate-or-override-the-android-back-button-in-flutter) – maxmitz Jul 04 '22 at 10:02
2 Answers
3
WillPopScope widget can detect your backpress
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async {
///your code here...
return false;
},
child:Scaffold(),
);
}

aswinbbc
- 161
- 4
0
You need to navigate it to your desired page after acquired the BACK event.
onPressed: () => Navigator.push(
context,
MaterialPageRoute(builder: (context) => Data()),

Krina chauhan
- 97
- 2
-
and how can i detect that the user pressed the button back of the phone ? – compte profe Jul 04 '22 at 10:16
-
Use WillPopScope method and return false. This method will detect BACK press. – Krina chauhan Jul 04 '22 at 10:45