flutter_web_router 1.0.2+1
flutter_web_router: ^1.0.2+1 copied to clipboard
[DISCONTINUED] A router that handles request URIs with wildcards and generate URIs with parameters.
This package is discontinued and will receive no further updates #
PLEASE NOTE: Use go_router instead.
flutter_web_router #
A router that handles request URIs with wildcards and generate URIs with parameters.
usage #
- Set up
WebRouter
final router = WebRouter();
copied to clipboard
If you want to show error pages, please add error pages.
router.addForbiddenRoute((request) => ForbiddenPage());
router.addNotFoundRoute((request) => NotFoundPage());
router.addInternalErrorRoute((request) => InternalErrorPage());
copied to clipboard
Please add URIs of page. You can add URIs with wildcards.
router.addRoute('/login', (request) => LoginPage());
router.addRoute('/', (request) => DashboardPage());
router.addRoute('items/index', (request) => ItemListPage());
router.addRoute('items/view/{itemId}', (request) => ItemViewPage(request: request));
copied to clipboard
If you want to verify a user, please add filters.
LoginVerificationFilter
is a sample class that implements WebFilter
class.
router.addFilter(LoginVerificationFilter());
copied to clipboard
Finally, you can set a transition.
// set OnComplete handler
router.setOnComplete((settings, widget) {
// fade transition
return PageRouteBuilder(
settings: settings,
pageBuilder: (_, __, ___) => widget,
transitionsBuilder: (_, anim, __, child) {
return FadeTransition(
opacity: anim,
child: child,
);
},
);
});
copied to clipboard
- set
router.build()
toonGenerateRoute
return MaterialApp(
...
onGenerateRoute: router.build(),
...
);
copied to clipboard
- navigate with
WebRequest
If you want to request URIs used wildcards, use WebRequest
.
final request = WebRequest.request(
'items/view/{itemId}',
data: {
'itemId': '1',
},
);
await Navigator.of(context).pushNamed(
request.uri.toString(),
);
copied to clipboard