openfoodfacts / smooth-app

🤳🥫 The new Open Food Facts mobile application for Android and iOS, crafted with Flutter and Dart
https://world.openfoodfacts.org/open-food-facts-mobile-app?utm_source=off&utf_medium=web&utm_campaign=github-repo
Apache License 2.0
821 stars 277 forks source link

Switching the navigator (deeplinking ?) #260

Closed M123-dev closed 3 years ago

M123-dev commented 3 years ago

At the moment we are using navigator 1.0 which simply builds the pages on top of each other with .push() and .pop() but there are already many alternatives which would be especially good if we want to add some kind of deeplinking to smoothie.

The easiest alternative would be named routes which are specified in the Material app.

MaterialApp(
  routes: {
    '/settings': (context) => Settings(),
    ExtractArgumentsScreen.routeName: (context) => ExtractArgumentsScreen(),
  },
);

//With data
onPressed: () {
      Navigator.pushNamed(
            context,
            ExtractArgumentsScreen.routeName,
            arguments: ScreenArguments(
              'Extract Arguments Screen',
              'This message is extracted in the build method.',
            ),
          );
}

//Without data
onPressed: () {
  Navigator.pushNamed(context, '/second');
}

Or we can use Navigator 2.0 which also allows to push and pop multiple pages at once, but it is way more complex and will use more time to get it to work. But when we plan to use deeplinking this would probably be the way to go. A good example here.

A official guide showing the differences can be found here

monsieurtanuki commented 3 years ago

@M123-dev Named routes are good, and may even enable deep-linking. But I'm rather in favor of letting immediate use-cases lead our choices of implementation, and not develop more complex and more powerful features "just in case". I can tell you this: my (dev) life started to be much easier the day I started to develop according to priorities first. By the time I arrived to lower priorities, most of the time they were not relevant anymore.

It's probable that one day we'll have to think about navigator 2.0, when we have a clearer view on the pages connections.

M123-dev commented 3 years ago

@monsieurtanuki okay then let's do it as you suggested and yes, starting small and continuing to develop is certainly a good idea