Last updated:
0 purchases
flutter annotation router
flutter_annotation_router #
Annotation-based route library.
Example #
Setup
/* replace you path */
import 'router.route.dart';
void main() {
setupGuards();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Annotation',
theme: ThemeData(
primarySwatch: Colors.blue,
),
initialRoute: RouteChain.shared.initialRoute,
onGenerateRoute: onGenerateRoute,
navigatorObservers: [
_FixNavigatorWithPop(),
],
);
}
class _FixNavigatorWithPop extends NavigatorObserver {
_FixNavigatorWithPop();
@override
void didPop(Route route, Route? previousRoute) {
final name = route.settings.name;
if (name != null && RouteChain.shared.routes.contains(name)) {
RouteChain.shared.pop();
}
super.didPop(route, previousRoute);
}
}
copied to clipboard
Router entry
@EnableAnnotationRouter()
@EnableNavigateHelper(enableRouteGuard: true)
class ApplicationRouter {}
copied to clipboard
Home page
@RoutePage('/', isRoot: true)
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
State<MyHomePage> createState() => _MyHomePageState();
}
copied to clipboard
Back home
context.backToHome();
copied to clipboard
Child page
@RoutePage('/first', alias: 'First')
class FirstPage extends StatefulWidget {}
copied to clipboard
Route method
@RoutePage('/second',
toSelfAndPopTo: true,
replacementToSelf: true,
backToSelf: true,
popAndToSelf: true)
class SecondPage extends StatelessWidget {}
copied to clipboard
Route parameter
@RouteValue()
final String text;
@RouteValue(defaultValue: true)
final bool? isModal;
@RouteValue(validate: r'\d+')
final int age;
copied to clipboard
Push page
/* replace you path */
import 'xxx.navigate.dart';
// toSelf: true
context.toSecondPage();
// toSelfAndPopTo: true
context.toSecondPageAndPopTo();
// replacementToSelf: true
context.replacementToSecondPage();
// backToSelf: true
context.backToSecondPage();
// popAndToSelf: true
context.popAndToSecondPage();
// default
context.popSecondPage();
copied to clipboard
Route listener
@RouteGuard('/*')
class RouteLoggingListener implements RouteListener {
@override
Future<bool> onEnter(String to, String? from, Map<String, dynamic> args) {
return Future.value(true);
}
@override
Future<bool> onLeave(String to, String from) {
return Future.value(true);
}
}
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.