Created
October 19, 2024 15:46
-
-
Save ajinzrathod/49d9b5cf6c577d6cdeb89f20ec522447 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{} | |
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()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment