Open enseitankad0 opened 1 year ago
With Dart 3 you use the new class modifier sealed for that.
sealed class UserState {}
final class LoadingState extends UserState {}
final class LoadedUserState extends UserState {}
final class UserErrorState extends UserState {}
You can now use exhaustive switching
builder: (context, state) {
return switch(state) {
LoadingState() => Text('LoadingUserState),
LoadedUserState() => Text(state.name),
UserErrorState() => Text('Error'),
}
}
If you forgot one state e.g. UserErrorState you will receive an error.
The type 'UserState' 'is not ex exhaustively matched by the switch case since it doesn't match UserErrorState()
Hi. I noticed that this is happening quite often when team member forgets to handle Error state coming from Bloc. Can we have special rule for it? Similar to list all props in equatable
get props
.