KaiselRoute is an abstract class with a const constructor, so every route must extend it. A sealed family whose variants carry no data is exactly an enum — but a Dart enum cannot extend a class, only implement interfaces and apply mixins.
// what you want
enum SettingsTab implements KaiselRoute { profile, security, about }
// what you must write
sealed class SettingsRoute extends KaiselRoute { const SettingsRoute._(); }
final class Profile extends SettingsRoute { const Profile() : super._(); }
final class Security extends SettingsRoute { const Security() : super._(); }
final class About extends SettingsRoute { const About() : super._(); }
Scale
In one 371-route app, 11 of 41 route families had no data on any variant. Those are pure enums expressed as sealed hierarchies — more code, and a lint (prefer_enum_over_sealed_class in that projects house rules) firing on each, requiring an ignore comment per file with an explanation of why the advice is impossible to follow.
Suggestion
Make KaiselRoute implementable — an abstract interface class, or a mixin providing props / routeName defaults — so enum Tab implements KaiselRoute { ... } is legal.
The pieces look compatible: props and routeName are both instance members with defaults, and enums can override both. The blocker is only the const constructor implied by extends.
Worth noting a workaround that is arguably better anyway, and could be documented either way: carry the enum as a field on a single route class.
final class Tab extends KaiselRoute {
const Tab(this.value);
final TabValue value;
@override
List<Object?> get props => [value];
}
Exhaustiveness then comes from switching on the enum rather than the sealed type, which is equivalent for the builder.
KaiselRouteis anabstract classwith a const constructor, so every route mustextendit. A sealed family whose variants carry no data is exactly an enum — but a Dart enum cannotextenda class, onlyimplementinterfaces and apply mixins.Scale
In one 371-route app, 11 of 41 route families had no data on any variant. Those are pure enums expressed as sealed hierarchies — more code, and a lint (
prefer_enum_over_sealed_classin that projects house rules) firing on each, requiring an ignore comment per file with an explanation of why the advice is impossible to follow.Suggestion
Make
KaiselRouteimplementable — anabstract interface class, or a mixin providingprops/routeNamedefaults — soenum Tab implements KaiselRoute { ... }is legal.The pieces look compatible:
propsandrouteNameare both instance members with defaults, and enums can override both. The blocker is only the const constructor implied byextends.Worth noting a workaround that is arguably better anyway, and could be documented either way: carry the enum as a field on a single route class.
Exhaustiveness then comes from switching on the enum rather than the sealed type, which is equivalent for the builder.