curiousgeek
curiousgeek

Reputation: 981

Flutter : Is provider an alternative to the BLoC pattern?

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.

Upvotes: 9

Views: 5664

Answers (1)

Suragch
Suragch

Reputation: 511576

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:

Upvotes: 11

Related Questions