Home > Back-end >  how to detect if the button back of the phone is pressed?
how to detect if the button back of the phone is pressed?

Time:07-05

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

CodePudding user response:

WillPopScope widget can detect your backpress

@override
Widget build(BuildContext context) {
  return WillPopScope(
    onWillPop: () async {
      ///your code here...
      return false;
    },
    child:Scaffold(), 
  );
}

CodePudding user response:

You need to navigate it to your desired page after acquired the BACK event.

onPressed: () => Navigator.push(
              context,
              MaterialPageRoute(builder: (context) => Data()),
  • Related