Last active
October 19, 2024 16:22
-
-
Save ajinzrathod/633625637354825f951c9e5796001845 to your computer and use it in GitHub Desktop.
sealed class without exhaustively matched
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed class LoginState {} | |
class LoginLoadingState extends LoginState{} | |
class LoginSuccessState extends LoginState{} | |
class LoginFailureState extends LoginState{} | |
class LoginRedirectState extends LoginState{} | |
void handleLoginState(LoginState state) { | |
switch(state) { | |
case LoginLoadingState(): | |
print('Logging in...'); // Handle loading state | |
break; | |
case LoginSuccessState(): | |
print('Welcome'); // Handle success state | |
break; | |
case LoginFailureState(): | |
print('Error'); // Handle failure state | |
break; | |
// no case for LoginRedirectState | |
} | |
} | |
void main() { | |
handleLoginState(LoginLoadingState()); | |
handleLoginState(LoginSuccessState()); | |
handleLoginState(LoginFailureState()); | |
handleLoginState(LoginRedirectState()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment