I have Flutter app with simple Provider and Consumer flow class SomeProvider with ChangeNotifier. My SubscriptionProvider has next methods:
methodA() async {
isLoading = true;
data = {};
notifyListeners();
await Future.delayed(Duration.zero, otherMethod);
methodB();
}
methodB() {
isLoading = false;
data = {
notifyListeners();
}
Widget Code:
Consumer<SomeProvider>(
builder: (ctx, someProvider, _) {
if (someProvider.isLoading) {
return WidgetC();
}
return WidgetD();
}
)
My problem is that when methodA is called build runs only once. On the other hand if I run await Future.delayed(Duration(seconds: 2), otherMethod); instead of await Future.delayed(Duration.zero, otherMethod); everything works fine and I have two builds. Are there any ways to perform build every time I call notifyListeners in provider.