Home > other >  How to use provider in a builder? FLUTTER
How to use provider in a builder? FLUTTER

Time:12-28

As a hobby and with the purpose of being better with provider I'm converting all the stateful widgets that I like into stateless widgets using provider. I perfectly understand simple cases, but now I have a problem with provider in builder. Here is where I use the provider (flipCardProvider.isBack)

Use Provider

And the error is the next one:

Provider Error

CodePudding user response:

I don't think calling notifyListeners() in builder is the right place, there must be a general design flaw and misconception about how the framework works. Yet as a workaround you can wrap the call in Timer() or Future.delayed() to have the update scheduled right after build() completion:

Timer(Duration(seconds: 0, () => notifyListeners())
  • Related