skip to Main Content

I want to achieve that creating a home page after login page. I have one feature that called "add new product." After I open "add new product" screen and filling text fields, I am expecting to Navigate to the main page and remove previous navigation adresses.

Because, when I navigate to home screen after "add new product" then click the "previous page" arrow on the left top of the screen (on appbar) it navigates me back to "add new product" screen.

I found that there is a funciton called pushAndRemoveUntil() I implemented it to my code.

 Navigator.pushAndRemoveUntil(
                                      context,
                                      SlideUpPageRoute(
                                          page: CategoryPage(
                                              categoryName: widget.categoryName,
                                              categoryID: widget
                                                  .categoryID)), // Yeni sayfa
                                      (Route<dynamic> route) => route
                                          .isFirst, // Tüm önceki sayfaları temizle
                                    );

and it works.

However, when I click "go back button on left side of appbar" it makes me go back to the login page(which is first navigation adress) not to the home page. It is annoying that logging in after one log in and I want to solve that.

I am aware that happens because of

 (Route<dynamic> route) => route.isFirst);

but first route should not be the login page because after succesful login I use
pushReplacement() not push()

my code for directing after login:

 String signInToken = await login.signInWithEmailAndPassword();
      if (signInToken == "succes") {
        Navigator.of(context).pushReplacement(
            SlideUpPageRoute(page: const HomePageCategories()));
      }

what is the reason for program still stores login page as a first route? Are there any other useful method for deploy home page after login page to my program (without using bloc or something I can’t afford that big change)

2

Answers


  1. Chosen as BEST ANSWER

    ok I found the answer thanks to chatgpt. to remove first route and replace it with something else you should use pushAndRemoveUntil() at the first place either.

    full code:

     Navigator.pushAndRemoveUntil(
          context,
          SlideUpPageRoute(page: HomePageCategories()),
          (route) => false,
        );
    

  2. i have some recommendation for you.
    first, maybe you use route package from pub dev, my high recommendation is auto_route package.

    but if you want use native routing system, then
    on LoginPage after it success you have to pushAndReplace the page. This action will remove the previous route and open another one.

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