Skip to content

feat: allow KaiselRoute to be implemented, so data-less route families can be enums #65

Description

@Mastersam07

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions