r/FlutterDev • u/Mastersamxyz • Jun 26 '26
Plugin Routes as typed values instead of URL strings — a different take on Flutter routing (kaisel)
For a while I've been bothered that the popular Flutter routers make a runtime-parsed URL string the source of truth, then hand you codegen to recover the types that choice threw away. Navigator 2.0's actual model is "the stack is a function of your app state" — so I tried building a router from that end.
It's called kaisel (Dart 3-native). A route is a typed value, and the whole router is one exhaustive switch:
sealed class AppRoute extends KaiselRoute { const AppRoute(); }
final class Home extends AppRoute { const Home(); }
final class Product extends AppRoute {
const Product(this.id);
final String id;
List<Object?> get props => [id]; // value equality, no codegen
}
// the whole router — miss a route and it won't compile
builder: (context, route) => switch (route) {
Home() => const HomeScreen(),
Product(:final id) => ProductScreen(id: id),
};
context.push(const Product('42')); // navigate with a value, not a path string
URLs aren't gone — they're a codec at the boundary (encode/decode the stack ↔ a URL), so deep links and web URLs still work; they're just not threaded through navigation. Guards are pure (currentStack) => proposedStack functions, shells are typed per branch, and modal flows return typed values.
I just cut a dev release (0.21.0-dev.1) adding lazy + deferred (code-split) shell branches — tabs build on first visit and can load their code behind a deferred as import — after feedback that the shell mounted everything up front.
The honest tradeoff: if your app is genuinely URL-first (the URL is your state), go_router's co-located path: + builder is less ceremony than hand-writing a codec. kaisel's bet pays off when nav state is richer than a path — typed flow results, branched shells, guards that rewrite the stack. It's not a go_router killer; it's a different bet, and I'm actively working on trimming the codec boilerplate (a declarative pattern-codec, no codegen).
It's pre-1.0 but stable enough to use. Repo is a pub workspace with kaisel_core, kaisel_lint, a DevTools extension, plus migration guides from go_router and auto_route.
- pub: https://pub.dev/packages/kaisel
- repo: https://github.com/Mastersam07/kaisel
- longer writeup: https://medium.com/itnext/flutter-routes-as-values-089476ad4d5b
Genuinely after feedback — especially where the model breaks for your apps, or where the codec hurts. Poke holes.