navigation_manager 1.0.0 navigation_manager: ^1.0.0 copied to clipboard
Navigation manager for Navigator 2.0 with a convenient declarative way to define application routes.
Navigation plugin #
Features #
- ✅ Navigator 2.0 support
- ✅ Duplicate strategies and tree concept
- ❌ Nested sub-trees
- ✅ Uri templates parsing. Check uri package and RFC 6570
- ❌ Global(ok) / per route transitions
Good to read #
- You could read sub-tree concept doc for better understand duplicate strategies.
Minimal Installation #
Define routes
// routes.dart
import 'package:flutter/material.dart';
import 'package:navigation_manager/navigation_manager.dart';
abstract class Routes {
static final main = AppRoute.subroot(
'/',
(Map<String, dynamic> data) => const YourPageWidget(),
duplicateStrategy: SubRootDuplicateStrategy.MakeVisible, // optional, default value
);
static final unknown = AppRoute(
'/404',
(data) => YourUnkwownRoutePage(),
duplicateStrategy: DuplicateStrategy.Ignore // optional, default value
);
static final appRoutes = [
main,
];
}
Setup navigator
// main.dart
import 'package:flutter/material.dart';
import 'package:navigation_manager/navigation_manager.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
late final RouteManager routeManager;
@override
void initState() {
routeManager = RouteManager(
initialRoute: Routes.main, // required
);
super.initState();
}
@override
Widget build(BuildContext context) {
return MaterialApp.router(
routerDelegate: AppRouteDelegate(
routeManager: routeManager, // required
),
routeInformationParser: AppRouteInformationParser(
unknownRoute: Routes.unknown, // required
routes: Routes.appRoutes, // required
),
);
}
}
And use them
routeManager.push(AppRoute, {Map<String, dynamic> data})
routeManager.pop()
/// Removes the specified route from the routes list.
/// If the specified route is sub-root then entire sub-tree will be deleted.
routeManager.remove(AppRoute)
/// Removes all routes from the routes list after the specified.
routeManager.removeUntil(AppRoute)