skip to Main Content

I have 4 page to navigate:
A > B > C > D

I use Navigator.pushReplacement for navigate from each page.
The problem is every first time run the app from vscode, when C > D it will be freeze and then I close the app from emulator and open it again (not re-run from vscode). It works well. Is this danger? what should I fix to make the app run smooth

Navigator.pushReplacement(
          context,
          CupertinoPageRoute(builder: (context) => Nextpages()),
        );

2

Answers


  1. Chosen as BEST ANSWER

    Thankyou guys for the help. Apparently it's my fold. The navigator push replacement method is fine, but I'm forget to dispose all controller. So it call an event but unfortunately the page is closed, that's make the error.


  2. I believe this is the correct way.

    Route:

            // A modal route that replaces the entire screen with a platform-adaptive transition.
            final MaterialPageRoute<dynamic> route = MaterialPageRoute<dynamic>(
              builder: (BuildContext context) {
                return const ScreenA(); // ScreenB or ScreenC or ScreenD
              },
            );
    

    Push:

            // Push the given route onto the navigator.
            await Navigator.of(context).push(route);
    

    Pop:

            // Pop the top-most route off the navigator.
            Navigator.of(context).pop();
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search