Last active
March 27, 2021 00:54
-
-
Save lukepighetti/85285136eacf1558761b98a9bb8c2c93 to your computer and use it in GitHub Desktop.
Simple route generator that exposes arguments and query params to route builders
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main() { | |
BuildContext context; | |
final router = NavigationService(context); | |
return MaterialApp( | |
onGenerateRoute: (settings) => router.handleGenerateRoute( | |
settings, | |
routes: { | |
'/': (params, context) => HomeView(), | |
/// You can get here with a few methods | |
/// | |
/// 1) Navigator.of(context).push('/inbox') | |
/// 2) Navigator.of(context.push('/inbox?thread_id=foo')) | |
/// 3) Navigator.of(context.push('/inbox', arguments: {'thread_id': 'foo'})) | |
/// | |
/// 4) router.to('/inbox') | |
/// 5) router.to('/inbox?thread_id=foo') | |
/// 6) router.to('/inbox', {'thread_id': 'foo'}) | |
'/inbox': (params, context) { | |
final threadId = params['thread_id']; | |
if (threadId != null) | |
return InboxView(threadId: threadId); | |
else | |
return InboxView(); | |
} | |
}, | |
), | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment