ShadyBoukhary / flutter_clean_architecture

Clean architecture flutter: A Flutter package that makes it easy and intuitive to implement Uncle Bob's Clean Architecture in Flutter. This package provides basic classes that are tuned to work with Flutter and are designed according to the Clean Architecture.
https://pub.dartlang.org/packages/flutter_clean_architecture
MIT License
691 stars 172 forks source link

RefreshUI and setState #69

Closed CROSP closed 3 years ago

CROSP commented 3 years ago

First of all, thank you for the library and spreading the Clean Architecture concept. It is unclear for me what should I do when I need UI to react to the change of a variable. For example the isLoading flag is triggered when a network call is executed, should I call the refreshUI method every time? Does this approach have any side effects related to performance?

I've also tried the following code:

this.getState().setState(()=> {})

But this throws an exception due to an uninitialised variable.

Please clarify what is the right way to update UI state?

Thank you.

ShadyBoukhary commented 3 years ago

You can use ControlledWidgetBuilder and refreshUI(). Please refer to the README for examples.

refreshUI will only refresh the widgets that are affected. This is the way this library handles state. It uses the Provider package internally.

Thanks