stacked icon indicating copy to clipboard operation
stacked copied to clipboard

How to use Stacked NavigationService with new auto_route syntax (1.0.2)

Open BrylleGomez opened this issue 5 years ago • 4 comments

Dear FilledStacks team,

First of all thank you for the awesome guides and awesome Stacked architecture! I have a question regarding the navigation component: the updated auto_route package (1.0.2) has a completely revamped syntax, and I am not quite sure how to use it with the Stacked NavigationService anymore. For context, I am following your "Complete Flutter Architecture using Provider and Stacked" written and YouTube tutorials.

In the documentation, initialRoute, onGenerateRoute, and navigatorKey are supplied in main.dart to the MaterialApp(). However, the new generated Router() class does not have the "Routes" variable anymore so I cannot call Routes.initialRouteName anymore. I also cannot call Router().onGenerateRoute anymore as it's not part of the generated Router() class anymore.

Hence, calling _navigationService.navigateTo('/home-view'); throws [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: You are trying to use contextless navigation without a GetMaterialApp or Get.key.

BrylleGomez avatar Mar 23 '21 08:03 BrylleGomez

as the error suggested, Stacked Service uses Get for Navigation, also Get afaik are based on Navigator 1.0 while Auto Route 1.0+ uses Navigator 2.0

alvinvin00 avatar Mar 23 '21 13:03 alvinvin00

@BrylleGomez that's the reason we moved it internally into stacked. It's not supportive of our setup going forward. If you see in this video we can now generate our own router StackedRouter and use that instead of the auto_route package.

FilledStacks avatar Mar 24 '21 03:03 FilledStacks

@BrylleGomez that's the reason we moved it internally into stacked. It's not supportive of our setup going forward. If you see in this video we can now generate our own router StackedRouter and use that instead of the auto_route package.

this was giving me a lot of trouble until I saw this video. Somehow I missed this change about the stacked package.

Chappie74 avatar Mar 24 '21 17:03 Chappie74

Ohhh I completely missed that new video! Pretty amazing that navigation is assimilated into the Stacked architecture. Thank you so much for the speedy response! Back to coding :3

BrylleGomez avatar Mar 24 '21 17:03 BrylleGomez