Git Product home page Git Product logo

navigator_20_example's Introduction

Navigator 2.0 examples

Web demo of Router usage.

Navigator 2.0 Pages API example and Router example.

The main point of these examples is to show how to extract basic navigation logic to separate class (e.g. ChangeNotifier). I'm using 2 approaches:

  • Pages API
  • Router widget

Both of them use separate PageManager (or RoutePageManager) to handle navigation stack.

Pages API

Navigator's Pages API is a convenient way to declaratively set navigation stack in your Flutter app. Take a look at the main.dart entry point and please notice custom PageManager class that is handling list of pages provided to Navigator.

Router widget

For more complex and robust needs you may use the Router widget. Simple implementation can be found in main_router.dart entry point. Take a look at the custom TheAppPath class storing typed path information and RoutePageManager handling list of pages provided to the Navigator.

Web address handling

Because the RoutePageManager is notifying the Router about its changes and the currentPath is used as currentConfiguration the address bar in the browser is reflecting the stack changes:

  @override
  TheAppPath get currentConfiguration => pageManager.currentPath;

More

Run on Flutter dev (1.23)

Presentation at Flutter Cracow (Sept. 17th, 2020)

Presentation at DevFest Poland 2020

Presentation at Geekle Cross-Platform Mobile Development Summit 2020

Special thanks to Simon Lightfoot and Andrew Coutts.

See more also in the Stocks app example using Router.

navigator_20_example's People

Contributors

orestesgaolin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

navigator_20_example's Issues

Nested navigation

Thank you for providing the examples, it's much appreciated. I have had a play around with the nested navigation with multiple routers, but I'm struggling to parse the name from the nested navigator into url via the TheAppRouteInformationParser.

Would you be able to provide an example of this? Thanks in advance.

Router implementation not behaving as expected

Looking in the design spec here

The delegate itself is a Listenable, which the Router widget is subscribed to. Whenever the delegate wants to change how the Navigator is configured (e.g. change the list of Pages provided to the Navigator), it notifies its listeners, which will cause the Router widget to rebuild. As part of that rebuild the Router asks the routerDelegate for a correctly configured Navigator instance, which the Router will incorporate into the tree.

This implies that "notifyListeners" on the RouterDelegate is SUPPOSED to force a rebuild of the navigator.
See line 44 in your MaterialApp.router implementation

In your example, (and in mine), I can't get the router to request a rebuild from the delegate simply by calling "notifyListeners". My router never even requests the FIRST navigator on app-start. I'm having to do what you've done (line 51) and wrap my navigator in it's own responsive (Consumer) builder.

Are the specs wrong or are you and I missing something in our implementation?

I'll link to this over on the flutter repo for their comments

Router example is not popping routes with browser back button

Hi, thanks for the examples.

I can't, however, get the router example to work properly.

If you navigate down through a few details pages, and then use the browser back button to navigate back out, you'll notice that:

  1. Pages are not popped off the stack. Instead, duplicates are added to the stack. If you go 1, 2, 3, 4, and hit the back button 4 times the stack ends up with 11 pages (via printing out pageManager.pages.length). It appears to work because when you hit the home page, the logic dictates that all the pages are cleared.

  2. onPopPage is never called. I'm not sure if/how the browser back button is supposed to hook in here, but it doesn't. So there is never a call to pageManager.didPop(...)

How are we supposed to handle the browser back button?

main_router Nav 2.0 web back button rebuild a widget already built

Hello,
Thank you very much for your example. With your code in main_router, and RoutePageManager, I see how to use Navigator 2.0 and navigating inside the app without having to rebuild all widgets inside pages.

However, DetailsPage are rebuilding when using browser back button.
(Sorry, gif was too big. Here mp4) : https://streamable.com/4hdtpf

I don't think that is what we w

DetailsPage use UniqueKey() to be identified. I try to remove the rebuild by changing it with a ValueKey(idDetailsPage) in my projet, but I got an error when pressing web back button to render a myDetailPage (which is a todo page)

Assertion failed:
../…/widgets/navigator.dart:3558
!keyReservation.contains(key)
is not true

in flutter/packages/flutter/lib/src/widgets/navigator.dart

  void _debugCheckDuplicatedPageKeys() {
    assert(() {
      final Set<Key> keyReservation = <Key>{};
      for (final Page<dynamic> page in widget.pages) {
        final LocalKey? key = page.key;
        if (key != null) {
          **assert(!keyReservation.contains(key));**
          keyReservation.add(key);
        }
      }
      return true;
    }());
  }

Do you have any clue to not rebuild a widget already build in, when pressing web back button ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.