Closed mflesh1 closed 4 years ago
Hi @mflesh1 π Thanks for opening an issue!
You can await the Navigator.push
and then add an event to the bloc to reload like:
await Navigator.of(context).push(...);
context.bloc<MyBloc>().add(DataRequested());
Hope that helps!
Closing for now but feel free to comment with additional questions and I'm happy to continue the conversation π
@felangel thanks for the response. I tried this but the event is not triggering the bloc, any ideas? What context is being used the BuildContext?
Hi @mflesh1 yup the BuildContext will allow you to access the bloc if you provided it via BlocProvider higher up in the tree.
Are you able to share a link to a sample app which illustrates the problem youβre facing? Thanks π
I receive this error when I try this.
E/flutter (11801): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: Looking up a deactivated widget's ancestor is unsafe.
E/flutter (11801): At this point the state of the widget's element tree is no longer stable.
E/flutter (11801): To safely refer to a widget's ancestor in its dispose() method, save a reference to the ancestor by calling dependOnInheritedWidgetOfExactType() in the widget's didChangeDependencies() method.
@mflesh1 can you share a sample app which illustrates the issue?
@mflesh1 I suspect you're manually calling dispose where you're proving the bloc. You shouldn't do that since the bloc will be disposed for you automatically by the BlocProvider
. π
@felangel it is hard to share a sample app as I can't share the app I am working on, I would need to deconstruct it a bit to share, I will see what I can do.
@felangel so I added an example project, it has a home page that has a list, you can then navigate to another page, when you come back I want the home page list to refresh. The sample works on the first time you navigate but on subsequent navigations it does not.
It is implemented in this file.
_navigate(BuildContext context, String route) {
locator<NavigationService>().navigateTo(route).then((value) {
BlocProvider.of<ScreenBloc>(context).add(ScreenRefreshEvent());
locator<NavigationService>().pop();
});
}
@mflesh1 try this
ScreenBloc screenbloc = BlocProvider.of<ScreenBloc>(context);
then in dispose
screenbloc.add(ScreenRefreshEvent());
@felangel why this wont work in dispose?
BlocProvider.of<ScreenBloc>(context).add(ScreenRefreshEvent());
Hi @mflesh1 π Thanks for opening an issue!
You can await the
Navigator.push
and then add an event to the bloc to reload like:await Navigator.of(context).push(...); context.bloc<MyBloc>().add(DataRequested());
Hope that helps!
Closing for now but feel free to comment with additional questions and I'm happy to continue the conversation π
What if I have 4 pages? I am updating the data on the fourth page, and how can I update the data on the first page?
I receive this error when I try this.
E/flutter (11801): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: Looking up a deactivated widget's ancestor is unsafe. E/flutter (11801): At this point the state of the widget's element tree is no longer stable. E/flutter (11801): To safely refer to a widget's ancestor in its dispose() method, save a reference to the ancestor by calling dependOnInheritedWidgetOfExactType() in the widget's didChangeDependencies() method.
having same issues! can you share how you solved this?
Hi @mflesh1 π Thanks for opening an issue!
You can await the
Navigator.push
and then add an event to the bloc to reload like:await Navigator.of(context).push(...); context.bloc<MyBloc>().add(DataRequested());
Hope that helps!
Closing for now but feel free to comment with additional questions and I'm happy to continue the conversation π
if i want to show data in text field then loading data after screen loaded does not work.
I am sure I am missing something.
I have a main screen that displays a data loaded from an API, this is loaded using the bloc pattern. The user then navigates (pop) to a second page.
The user then can hit the back arrow to return to the original page at which point I want to reload (hit api using bloc) the data.
I can't seem to figure out how to do this.