1

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

  • 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 Answers2

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()),