Dart Sealed Classes Guide — Type-Safe State Management with Pattern Matching
Dart 3's sealed classes are the evolution of enums. They restrict subtyping to a closed set and enforce exhaustive switch coverage. The result: fewer runtime errors, richer domain models, cleaner state machines.
Basic Sealed Class
sealed class AuthState {}
class AuthInitial extends AuthState {} class AuthLoading extends AuthState {}
class AuthSuccess extends AuthState { final String userId ; final String email ; AuthSuccess ({ required this . userId , required this . email }); }
class AuthError extends AuthState { final String message ; final String ? code ; AuthError ({ required this . message , this .…