2


I don't understand how to use updateShouldNotify in StreamProvider.

(new) StreamProvider StreamProvider({Key key}, {Stream Function(BuildContext) create}, {FirebaseUser initialData}, {FirebaseUser Function(BuildContext, Object) catchError}, {bool Function(FirebaseUser, FirebaseUser) updateShouldNotify}, {bool lazy}, {Widget child})

I didn't get much help in the doc https://pub.dev/documentation/provider/latest/provider/StreamProvider-class.html

Help plz :D

Dimitri Leurs
  • 590
  • 5
  • 19

1 Answers1

0

You have the answer from Rémi Rousselet himself (the creator of the Provider package) here:

https://stackoverflow.com/questions/57365207/streamprovider-not-updating-state

The default behavior of most providers (excluding ChangeNotifierProvider) is to assume that the values passed are immutable. As such, if your stream emits the same value as previously emitted, this won't rebuild dependents.

The default behaviour of updateShouldNotify is the following, you can find an exemple here: https://www.didierboelens.com/2019/07/provider-points-of-interest-points-to-care-about

updateShouldNotify: (previous, current) => (current != previous),

You don't need to use/override the parameter if this behaviour is good for you. However, if you want to change this default behaviour to update everytime there is a new value (no matter if it's the same or a new one), override it by using the parameter:

updateShouldNotify: (_, __) => true
Jerbs
  • 131
  • 1
  • 8