2

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

4
  • Navigator.pop(context) ? Commented Aug 29, 2021 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 . Commented Aug 29, 2021 at 11:15
  • What kind of navigation are you using then ? Some code would help. Commented Aug 29, 2021 at 11:16
  • I think this will help you to figure out programmatically exit the app Commented Aug 29, 2021 at 11:24

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.