Hi ,
I faced this error when visit page again
steps: open page -> back -> open page again
I read other guys asked about this error, but in my code I didn't dispose any bloc because I use BlocProvider in the routes config
routes: {
HomepagePage.routeName: (BuildContext context) =>
BlocProvider<HomepageBloc>(
builder: (context) => HomepageBloc(),
child: HomepagePage(),
),
OnboardingScreen.routeName: (BuildContext context) =>
OnboardingScreen(),
ProductDetailPage.routeName: (BuildContext context) =>
BlocProvider<ProductDetailBloc>(
builder: (context) => ProductDetailBloc(),
child: ProductDetailPage(),
),
ProductListPage.routeName: (BuildContext context) =>
BlocProvider<ProductListBloc>(
builder: (context) => ProductListBloc(),
child: ProductListPage(),
),
LoginPage.routeName: (BuildContext context) =>
BlocProvider<LoginBloc>(
builder: (context) => LoginBloc(),
child: LoginPage(),
)
}
And in your release blog I found that it is automatically disposed.
As you can see, we no longer have to worry about disposing our blocs! As long as they are created by BlocProvider they will be disposed by BlocProvider automatically 馃帀.
But if it is automatically disposed, how can I deal with above error. Thanks
just found the reason:
This is because I am using a Singleton bloc for the screen. So it is not getting initialized once the screen is going out of the Widget tree.
The bloc template from https://github.com/Gorniv/vscode-flutter-files uses singleton bloc.
I think it need to be updated.
@nguyenhuutinh thanks for the update. I would recommend opening an issue on that repo as it is maintained by a third party. You can check out the official vscode extension if you haven't already 馃憤
yes, I already reported bug to him. thanks
Most helpful comment
yes, I already reported bug to him. thanks