Flutter Navigator 2.0 and Deep Links | raywenderlich.com

Thanks for letting me know. It had old files. Iā€™ve updated the project, so give it a try now

@kevindmoore May I know how to declare AppState on launch and to assign it to delegate. I have gone through the final code, but I didnā€™t come across AppState class. Kindly could you please update it?

Can you try downloading again, the wrong version of the code was there.

1 Like

Whatā€™s the difference between addWidget and addPage method?

The addPage method adds the page given by the currentAction.page variable. A new page is created. addWidget passes in an already created widget. This is needed for widgets that take arguments or need to be created before hand.

A few comments:

Error in a snippet:

@override
Future<void> setNewRoutePath(PageConfiguration pageData) {
  final shouldAddPage = _pages.isEmpty ||
      (_pages.last.arguments as PageConfiguration).uiPage !=
          configuration.uiPage;
  if (shouldAddPage) {
    _pages.clear();
    addPage(configuration);
  }
  return SynchronousFuture(null);
}

pageData should be renamed to configuration.

The hosted code (downloaded from the link on top of the page) is in a different version compared to the article: PageConfiguration is missing PageAction.

ShoppingRouterDelegate snippet does not have a 9. point, but it is mentioned in the description of the snippet.

I will let you know if I find more.

Good catch. Iā€™ve updated the article with your changes. Thanks!

1 Like

After touring several tutorials (this tuto also) and packages about Navigator, , I made my own solution that I find more simple.
I post it if it helps anyone.

Has anyone else had problems with this code since upgrading to Flutter 2.2+? Suddenly after updating to null safety, my URL is not updating correctly, itā€™s always 1 page behind. For example, after setSplashFinished, the url still reads /splash, even though it is showing the Login screen. Then if I navigate to a new screen from Login, the URL shows /login instead of the current screen.

I think itā€™s because the routerDelegate currentConfiguration value isnā€™t updating correctly, but I cannot seem to figure it out.

I did a test and converted the project to be null safe and up to date and it works fine.

I have done this tuto and I have same pb as mentioned apdos, any update ? Moreover, if you update url manually, this is not working. Thanks.

We are now working on an update to this article. Stay tuned.

Hi,

What is the difference between onPopPage (On Navigator constructor) and popRoute method (From RouterDelegate).

When is each of them called?

Hi. Can someone bring some light on whatā€™s going on in this piece:

  ShoppingRouterDelegate(this.appState) : navigatorKey = GlobalKey() {
    appState.addListener(() {
      notifyListeners();
    });
  }

Why is notifyListeners() passed to addListener?

The addListener call is being passed in a function. Notice the () {. This function will get called whenever the state changes. When that happens, the ShoppingRouterDelegate will notify itā€™s listeners that it changed.

Thank you for your answer, however Iā€™m struggling to find anything that listens to ShoppingRouterDelegate in the code. Could you also explain, where should I look to find an instance that listens to ShoppingRouterDelegate?

UPD. Ok, I got it. Itā€™s Router, that listens.

P.S. Great article to learn flutter in general btw. Being novice I took a lot of different insights. Reminds me in a way of ā€œDive into Pythonā€ )

Since ShoppingRouterDelegate is part of the navigator system, when you make calls like Navigator.pop() or push, the delegate is involved.

Appreciate that. And since you are so generous with answers - I swear, the last one ā€“ how come AppState() constructor has no initializers?

Also isnā€™t it a typo when two methods both use ā€˜addā€™ in here:

  void addToCart(String item) {
    cartItems.add(item);
    notifyListeners();
  }

  void removeFromCart(String item) {
    cartItems.add(item);
    notifyListeners();
  }

UPD:
Sorry, Iā€™m not allowed to post anymore in this topic. What I meant was when I declare some class in Visual Studio it demands that I shoud be

adding an initializer expression, or add a field initializer in this constructor

Good catch on the removeFromCart. That should be remove.
AppStateā€™s constructor looks like:

  AppState() {
    getLoggedInState();
  }

What do you mean by not having initializers?

Thatā€™s me again. What I meant was when I declare some class in Visual Studio it demands that I shoud be

adding an initializer expression, or add a field initializer in this constructor