Navgator.push... creating two instances of widget

Viewed 38

I'm doing some calls to the backend when a user clicks sign up that will create a new user and on success I want to route them to our onboarding page.

onTap: () {
  controller.checkSignUp("mobile").whenComplete(() {
    return Navigator.of(context)
          .pushNamed('/onboarding');
  });
},

However, the widget associated with the /onboarding route will always have two instances created UNLESS I step through the async calls in checkSignUp slowly in debug mode. There is an instance of PageController that can only have one PageView attached to it so because two instances are created, the widget breaks.

Anyone have any idea on why this could be? I've also tried the above code using async/await with no luck

2 Answers

I couldn't figure out why two instances were created but I fixed it by using the PageController api to check to see how many views were attached to it and removed the first one if there was more than 1 attached.

I think the return is the problem. Don't need a return to use Navigation.

Related