I know that BLoC in flutter acts like the viewmodel layer in android's MVVM, so the data does not gets fetched again and again upon configuration changes (for ex: change in screen orientation).
I am confused if provider replaces the functionality of RxDart in BLoC pattern or it replaces the role BLoC pattern itself.
Also, if I don't use BLoC at all an only providers does the app survives configuration changes.
Please explain what are the limitations of provider over BLoC, RxDart combination with some use cases.
So here, we can compare the StreamBuilder in Bloc with Consumer in Provider. The difference is that StreamBuilder listens to the stream and fetches the model on every change to rebuild the widget. But Consumer listens as soon as notifyListeners() executes inside the provider class.
It's depends on you. If you are a beginner, I would say start with provider. Then learn about Bloc.
BlocProvider is a flutter widget that creates and provides a Bloc to all of its children. This is known as a dependency injection widget, so that a single instance of Bloc can be provided to multiple widgets within a subtree.
It seems GetX is simpler than Provider and has more capabilities/features like navigation, but there are not a lot of codes/tutorials using that!
Provider in itself doesn't replace the BLoC pattern. However, you can set up your architecture to use Provider in a way that could replace the BLoC pattern.
One way to do that would be to use the MVVM pattern, where you have a view model class that extends a ChangeNotifier. Then you can listen to that view model with a ChangeNotifierProvider so that the UI gets rebuilt any time the view model changes. FilledStacks does that well here.
See also
Personally I find it easier to use the builtin Flutter tools to manage state. I describe that more here:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With