I don't know if using runtimeTypeis a good approach for using switch for states
switch (state.runtimeType) {
case LoginStoredState:
Navigator.of(context).pushReplacementNamed(PAGE_DASHBOARD);
break;
case LoginFailedState:
showSnackBar((state as LoginFailedState).loginModel.message);
break;
}
if (state is LoginStoredState) {
Navigator.of(context).pushReplacementNamed(PAGE_DASHBOARD);
} else if (state is LoginFailedState) {
showSnackBar(state.loginModel.message);
}
Hi @amreniouinnovent 馃憢
Thanks for opening an issue!
While it is definitely possible to switch on runtimeType I personally would not recommend it because runtimeType can be overridden so ideally you should not have logic that depends on runtimeType.
In simple cases, you can represent your state as an enum and switch on the enum. I'm currently trying to investigate several implementations of sealed classes in Dart and will hopefully be able to address this in the upcoming releases.
Most helpful comment
Hi @amreniouinnovent 馃憢
Thanks for opening an issue!
While it is definitely possible to switch on
runtimeTypeI personally would not recommend it becauseruntimeTypecan be overridden so ideally you should not have logic that depends onruntimeType.In simple cases, you can represent your state as an enum and switch on the enum. I'm currently trying to investigate several implementations of sealed classes in Dart and will hopefully be able to address this in the upcoming releases.