Flutter : Is provider an alternative to the BLoC pattern?
Asked Answered
T

1

9

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.

Thirddegree answered 10/6, 2019 at 21:7 Comment(1)
"Provider is a dependency injection system built with widgets for widgets. provider is mostly syntax sugar for InheritedWidget, to make common use-cases straightforward." - BLoC is a pattern. They can be combined.Froggy
H
11

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:

Hapten answered 9/11, 2019 at 8:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.