flutter_annotation_router 0.0.1 copy "flutter_annotation_router: ^0.0.1" to clipboard
flutter_annotation_router: ^0.0.1 copied to clipboard

Annotation-based route library.

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);
  }
}
  • Router entry
@EnableAnnotationRouter()
@EnableNavigateHelper(enableRouteGuard: true)
class ApplicationRouter {}
  • Home page
@RoutePage('/', isRoot: true)
class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key}) : super(key: key);

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}
  • Back home
context.backToHome();
  • Child page
@RoutePage('/first', alias: 'First')
class FirstPage extends StatefulWidget {}
  • Route method
@RoutePage('/second',
    toSelfAndPopTo: true,
    replacementToSelf: true,
    backToSelf: true,
    popAndToSelf: true)
class SecondPage extends StatelessWidget {}
  • Route parameter
@RouteValue()
final String text;

@RouteValue(defaultValue: true)
final bool? isModal;

@RouteValue(validate: r'\d+')
final int age;
  • 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();
  • 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);
  }
}
1
likes
140
points
48
downloads

Publisher

unverified uploader

Weekly Downloads

Annotation-based route library.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

More

Packages that depend on flutter_annotation_router