Error: "Bad state: No element" when using BLoC_pattern with a bool value
I had the same issue when trying to access the first element of an empty iterable.
@overrideWidget build(BuildContext context) { return BlocProvider<MyBloc>( create: (context) { var list = myIterable.keys.first; // keys was empty var myBloc = MyBloc(); return myBloc; } return schuldenBloc; }, );}
The error Bad state: No element was happening because I'm trying to get the first
item of an empty iterable keys
inside the BlocProvider
.
var list = myIterable.keys.first; // keys was empty
you forgot to inform the StreamBuilder type, in this case is StreamBuilder<bool>()
I think that's the problem.