skip to Main Content

I used willPopScope but doesn’t work. Has anybody any other idea what can I use to overwrite the default back button of Android in Android Studio

The actual result: When I click the back button, it redirects to the login page, not to the page I want.

Does anybody has any other idea about this to function?

2

Answers


  1. Chosen as BEST ANSWER

    It did not work. I have used this method with the route name:

    void navigateToEventScreen() {
        Navigator.of(context).pushNamed('/');
      }
    
      @override
      Widget build(BuildContext context) {
        BlocProvider.of<PastHuddleCubit>(context).fetchPastHuddles();
        return WillPopScope(
          onWillPop: () async {
            navigateToEventScreen();
            return false;
          },
          child: Scaffold(
            appBar: ProfileAppBar(
              screenTitle: AppLocalizations.of(context)!.huddleScreenTitle,
            ),
    

    .....


  2. You may consider using a route system to avoid this behavior as follows: Navigate with named routes
    or check out if you’re in Stateful widget as this is suggested in this previous answer

    Hope this helps.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search