I have one common state where I need to handle multiple states like the Loading state and Error state.
All other states should have access to both states. So I can re-use these states to base screen and handle those states at single place.
Below is the common state
abstract class CommonState{}
class InitialState extends CommonState{
}
class UnauthorizedState extends CommonState{
}
class LoadingState extends CommonState{
String? loadingMessage;
LoadingState({this.loadingMessage});
}
class ErrorState extends CommonState{
String? errorMessage;
ErrorState({this.errorMessage});
}
I have added the cubit for the common state as below.
class CommonCubit<S extends CommonState> extends Cubit<S>{
CommonCubit(S initialState) : super(initialState);
}
I want to use this common cubit and state it everywhere in the app. Can use LoadingState, and ErrorState everywhere. I have tried the below approach but it is not working.
Below is the Login screen state.
class LoginState extends CommonState {}
class UserAuthorized extends LoginState {}
class UserUnauthorized extends LoginState {}
Below is the cubit for the login screen
class LoginCubit extends Cubit<LoginState>{
LoginCubit() : super( InitialState() ) {
checkUserAuthorized();
}
void checkUserAuthorized() {
emit(UnauthorizedState());
}
}
Here, I am getting an error that "The argument type InitialState can't be assigned to the parameter type LoginState. " So not getting how can I achieve this part. Can anyone please help me with this?
Please check above details.