In a typical BlocBuilder implementation what should i return when an unknown state is passed?
BlocBuilder(
bloc: _userBloc,
builder: (BuildContext context, UserState state) {
if (state is UserLoading) {
return LoadingIndicator();
}
if (state is UserSuccess) {
return LessonsPage(userBloc: _userBloc,);
}
})
The new master channel of flutter now the flutter analyse raise an issue if the callback have no return, what should i return in this case?
Hi @nerder 馃憢
Thanks for opening an issue and great question!
It's totally up to you, but a couple of options are:
if/else if/else instead of just ifErrorWidget which throws a FlutterErrorContainer()Hope that helps 馃憤
I don't even see how an unknown state might be passed since i'm the one defining them 馃ぃbut at static code analysis it makes sense to complain 馃槃
i like the ErrorWidget approach, because it mean that i forget to implement a UI for a possible state, so i want it to fail fast.
Thank you for your fast reply
Most helpful comment
I don't even see how an unknown state might be passed since i'm the one defining them 馃ぃbut at static code analysis it makes sense to complain 馃槃
i like the
ErrorWidgetapproach, because it mean that i forget to implement a UI for a possible state, so i want it to fail fast.Thank you for your fast reply