Skip to main content

smf_go_router 0.5.0 copy "smf_go_router: ^0.5.0" to clipboard
smf_go_router: ^0.5.0 copied to clipboard

The SMF module that routes the Flutter app that SMF generates with go_router. It renders the routes that the modules of the app declare and the router behind their navigation.

example/README.md

Generate a Flutter app with go_router #

go_router is the module of the SMF CLI that routes the app with go_router. Choose it with -m, here with the start screen home:

dart pub global activate smf_flutter_cli
smf create my_app -m go_router,home --no-input

The module adds go_router to the pubspec.yaml of the app, and lib/core/router/app_router_factory.dart, which turns the routes of the features into a GoRouter:

@override
late final GoRouter config = _GoRouter(
  initialLocation: '/home',
  observers: _observers(),
  routes: [
    GoRoute(path: '/', redirect: (context, state) => '/home'),
    GoRoute(
      path: '/home',
      name: 'home.home',
      builder: (context, state) => const screen0.HomeScreen(),
    ),
  ],
)..routerDelegate.addListener(_pagesChanged);

_GoRouter is a class of that file that extends GoRouter, so that the back button of the system works on the error screen of go_router too.

Screens navigate with context.nav, such as context.nav.home.home().go(), which the router role writes into lib/core/router/navigation.dart. It does not name go_router, so the screens of a feature work with any router. With a layout such as bottom_tabs, the router builds the main navigation with a branch for each tab.

A feature needs a router, so smf create -m home adds go_router by itself while it is the only module that provides the router. Without -m, smf create asks which module provides the router.

The documentation has more on the go_router module and on navigation in the generated app.

0
likes
160
points
1.1k
downloads

Documentation

Documentation
API reference

Publisher

verified publishersaymyframe.com

Weekly Downloads

The SMF module that routes the Flutter app that SMF generates with go_router. It renders the routes that the modules of the app declare and the router behind their navigation.

Homepage
Repository (GitHub)
View/report issues
Contributing

Topics

#flutter #routing #go-router #navigation

License

Apache-2.0 (license)

Dependencies

mason, smf_contracts

More

Packages that depend on smf_go_router