When To Actually Close A Bloc Manually When Using The Flutter_bloc Package?
I have a bit of confusion regarding closing the bloc manually in the dispose method. I heard from the speech that we don't have to call the dispose method for the blocs if we are using the flutter_bloc package, please correct me if this is wrong.
Thanks in advance
When you use
BlocProvider with a builder, the
BlocProvider is taking a responsibility for creating and closing a Bloc. In cases, where you want to provide an existing bloc to a new route, you should use
BlocProvider.value instead as it does not automatically close the bloc.
You can refer to documentation
In most cases, BlocProvider should be used to create new blocs which will be made available to the rest of the subtree. In this case, since BlocProvider is responsible for creating the bloc, it will automatically handle closing the bloc.
In some cases, BlocProvider can be used to provide an existing bloc to a new portion of the widget tree. This will be most commonly used when an existing bloc needs to be made available to a new route. In this case, BlocProvider will not automatically close the bloc since it did not create it.
- → How do you create a 12 or 24 mnemonics code for multiple cryptocurrencies (ETH, BTC and so on..)
- → Flutter: input text field don't work properly in a simple example..... where am I wrong?
- → Can I customize the code formatting of Dart code in Atom?
- → Is it possible to develop iOS apps with Flutter on a Linux virtual machine?
- → Display SnackBar in Flutter
- → JSON ObjectMapper in Flutter
- → Material flutter app source code
- → TabBarSelection No such method error
- → How do I set the animation color of a LinearProgressIndicator?
- → Add different routes/screens to Flutter app
- → Is there a way to get the size of an existing widget?
- → How to share a file using flutter
- → Is there an easy way to find particular text built from RichText in a Flutter test?