Skip to content

Navigator.popUntil in WillPopCallback breaks the navigation #3

Open
@EdStepashkin

Description

@EdStepashkin

I encountered an issue where using Navigator.popUntil inside a WillPopScope (WillPopCallback) seems to break the navigation flow in my Flutter app.

Here are the details:

  1. Navigate to a screen using 'MaterialPageRoute'.

    Example
           Navigator.push(
                   context,
                   MaterialPageRoute(builder: (context) => ScreenC()),
                 );
       
  2. Implement a WillPopScope with onWillPop that contains Navigator.popUntil.

    Example
       @override
         Widget build(BuildContext context) {
           return WillPopScope(
             onWillPop: () async {
               Navigator.popUntil(
                 context,
                 (route) => route.isFirst,
               );
               return false;
             },
             child: Container(),
           );
         }
       
  3. Use the back gesture to navigate back.

Actual Behavior:
Instead, the navigation behaves unexpectedly, and I encounter issues with the navigation flow.
On my real project the screen freezes completely and is unresponsive.
On example project after swipe-to-go-back the navigation doesn't work anymore.

Video Problem with ScreenA where I'm trying to navigate to ScreenA https://github.com/fluttercandies/ios_willpop_transition_theme/assets/22656185/0f636e7a-82e9-41c6-bdc6-94f4dea85342

Expected Behavior:

I expect the app to navigate back to the desired route.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions