Last active
October 19, 2024 16:23
-
-
Save ajinzrathod/4e739bdba9e8d57b1a63356512bb4488 to your computer and use it in GitHub Desktop.
Abstract Class example
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
abstract class LoginState {} | |
class LoginLoadingState extends LoginState{} | |
class LoginSuccessState extends LoginState{} | |
class LoginFailureState extends LoginState{} | |
class LoginRedirectState extends LoginState{} // added now | |
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; | |
} | |
} | |
void main() { | |
handleLoginState(LoginLoadingState()); | |
handleLoginState(LoginSuccessState()); | |
handleLoginState(LoginFailureState()); | |
handleLoginState(LoginRedirectState()); // added now | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment