whenStateChanged method

  1. @override
void whenStateChanged(
  1. S previous,
  2. S current,
  3. VoidCallback reBuild
)

Called when the notifier's state changes.

Implement this to determine when to trigger a rebuild based on state changes. previous is the previous state, current is the new state, and reBuild is a callback to trigger a rebuild.

Implementation

@override
void whenStateChanged(S previous, S current, VoidCallback reBuild) {
  if (buildWhen?.call(previous, current) ?? true) reBuild();
  if (listenWhen?.call(previous, current) ?? true) listener(current);
}