How to use back button function in Flutter?

Viewed 287

I want to back programmatically without press back button , ("trigger back button functionality without pressing it ") ?

1 Answers

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

Related