named_routes 0.2.0
named_routes: ^0.2.0 copied to clipboard
Add names to routes without a declarative design pattern and without build_runner
named_routes #
This opinionated package provides extension methods for BuildContext to push routes.
...and automatically add a name to the route so you can track it in sentry!
Overview #
NO to declaration of all routes aka go_router
NO to build_runner
YES to type-safety (we call widget constructors directly)
YES to sentry integration (named routes)
I just want to push a widget and that's it!
The problems without this package:
- Pushing a new route requires lots of boilerplate.
- Adding a name to the route requires you to write things twice (redundancy).
Navigator.push<T>(
context,
MaterialPageRoute(
builder: (_) => LoginPage(),
settings: RouteSettings(name: 'LoginPage'), // so redundant!
),
);
Now you only need to write:
context.push(() => LoginPage());
Usage #
// push a new route
context.push(() => MyPage());
// push a route while removing all others
context.pushRoot(() => MyPage());
// push a route while removing all others (without animation)
context.pushRootNoAnimation(() => MyPage());
// pop the most recent route
context.pop();
Sentry #
You want it to look like this?

MaterialApp(
navigatorObservers: [
SentryNavigatorObserver(), // add this
],
home: const InitPage(),
);
Obfuscation #
It does not work if you obfuscate the classes.
It is up to you. I don't value obfuscation that much.
Compiled flutter code is already hard to read.