Dani
Dani

Reputation: 4186

Flutter: duplicate notifyListeners()

I use a provider to share my global information across my app. Sometimes I need to update the UI with notifyListeners() but I end up calling different functions with a notifyListeners() on each of them.

In terms of performance, am I doing something wrong here? Should I cancel all of these notifyListeners()s and leave only the last one maybe?

Upvotes: 1

Views: 421

Answers (1)

lbarqueira
lbarqueira

Reputation: 1305

You are doing right. For each method with a notifyListener() you call it every time you need. You may have as much methods as you want with notifyListener(). However, where do you put the Provider in the widget tree, and where do you put the Consumer is the real issue in terms of performance.

Upvotes: 1

Related Questions