Last updated:
0 purchases
flutter nop
state manager & route generator #
example: router_demo
state manager #
nop version:
class CounterState {}
//...
Nav.put(() => CounterState());
//...
final app = MaterialApp(
...
navigatorObservers: [
...,
Nav.observer,
]
...
);
runApp(app);
//...
Widget build(BuildContext context) {
final counter = context.getType<CounterState>();
//...
}
copied to clipboard
router version:
example: router_demo
class CounterState {}
final router = NRouter( ... );
//...
router.put(() => CounterState());
//...
final app = MaterialApp.router(
routerConfig: router,
// ...
);
runApp(app);
//...
Widget build(BuildContext context) {
final counter = context.grass<CounterState>();
//...
}
copied to clipboard
route generator #
pubspec.yaml:
dependencies:
nop_annotations:
dev_dependencies:
nop_gen:
build_runner:
copied to clipboard
nop version:
link: route_gen
// routes.dart
import 'package:nop_annotations/nop_annotations.dart';
part 'routes.g.dart';
@NopRouteMain(
main: MyHomePage,
pages: [
RouteItem(page: SecondPage),
RouteItem(page: ThirdPage),
],
)
class AppRoutes {}
class SecondPage extends StatelessWidget {
const SecondPage({super.key, String? title});
//...
}
copied to clipboard
dart run build_runner build
copied to clipboard
// 'routes.g.dart'
class Routes {
//...
static final _secondPage = NopRoute(
name: '/secondPage',
fullName: '/secondPage',
builder: (context, arguments) => const Nop.page(
child: SecondPage(title: arguments['title']),
),
);
}
class NavRoutes {
static NopRouteAction<T> secondPage<T>({
BuildContext? context, String? title,
}) {
return NopRouteAction(
context: context, route: Routes._secondPage, arguments: {'title': title});
}
}
copied to clipboard
router version:
router_demo
dart run build_runner build --delete-conflicting-outputs
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.