Mastersam07 / Mastersam07/kaisel

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

Open
#65 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement pkg:kaisel_core
Dominant language
Dart
Stars
69
Forks
2
Avg merge
18m
Merged PRs (30d)
9

Description

`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.

```dart
// 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.

```dart
final class Tab extends KaiselRoute {
const Tab(this.value);
final TabValue value;
@override
List get props => [value];
}
```

Exhaustiveness then comes from switching on the enum rather than the sealed type, which is equivalent for the builder.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the KaiselRoute declaration and inspect how its props, routeName, and const-constructor requirements are used by route implementations. Check the existing test suite before evaluating whether enums can implement the route contract without breaking sealed route families. Done means the requested enum form is supported or the documented single-route-class workaround is clearly established, with existing routing behavior preserved.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, flutter
Domain
mobile
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.