I'm using bloc with clean architecture.
The scenario:
I have this list from list I'm choosing on item then go to item screen (in this screen the number of requests displayed in red circle). when clicking the red circle i go to reuest screen where i can accept/decline request. when i go back i want the number in red circle to change.
My Solution & the issue:
so i can catch up with the changes from request screen and display it in details screen. I decided to use one RequestBloc Instance above the details screen. so in details screen& request screen i read the bloc from context. and that worked for me. but in one direction. so after accepting a request and go back to details screens the number of request changed,but when i try to go to request screen again I got this issue
** "StateError was thrown building _InheritedProviderScope<RequestsBloc?>(listening to value): Bad state: Cannot add new events after calling close"**
Some code: from list i go like this
onTap: () {
context.push(Routes.detailsRoute,
extra: ProductExtra(bloc: instance<RequestsBloc>(), Product: product));
},
in route file
return BlocProvider.value(
value:productExtra.bloc,
child: ProductDetailsScreen(Product: productExtra.product));
in details screen
//read the bloc
_RequestsBloc = context.read<RequestsBloc>();
go to request screen
context.push(Routes.requestRoute, extra: productExtra);
in routes file
return BlocProvider.value(
value: productExtra.bloc,
child: RequestsScreen());
in request screen i also read the bloc from context.
in general i tried to change the blocProvider value from level to level