In the past I successfully used switch auto completing for creating all the missing cases. But after migrating to the dart 3 that's feature not work yet. All what I see - the error message about missing cases. Anybody know something more about it. And may be there is some snippets to creating switch with all the cases of enum or sealed class. (Without default case of course). Thank you!
enum MyColors { red, green, blue }
extension on MyColors {
Color of(BuildContext context) => switch (this) {
MyColors.red => context.colors.red,
};
Color of2(BuildContext context) {
switch (this) {
case MyColors.red:
return context.colors.red;
}
}
}
Thats code example only for question illustration.
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.10.2, on macOS 13.4 22F66 darwin-arm64, locale uk-UA)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 14.3)
[✓] Android Studio (version 2022.2)
[✓] Connected device (1 available)
[✓] Network resources
• No issues found!
This is a known issue with the Dart 3 release. Something to do with the exhaustiveness algorithm with the introduction of pattern matching. By the sound of it, seems like a hard problem that I wouldn't expect it to be fixed any time soon. Otherwise, they would have done so before release. In the mean time, best to just add each case manually. And follow the issue threads from the dart team to be updated on a fix in future releases.
https://github.com/dart-lang/sdk/issues/52180
Quote from one of the dart team members:
Unfortunately, that behavior is the best we can do at the moment. With the switch to patterns we had to write a much more general algorithm to compute exhaustiveness, and that algorithm currently only finds the first case that isn't covered. There have been discussions about extending the algorithm to find all of the missing cases so that we can do a better job, but I don't know what the state of that work is.
The flutter team also are aware of this issue:
https://github.com/flutter/flutter-intellij/issues/6812
All we can do is wait.