updateShouldNotify method Null safety

  1. @override
bool updateShouldNotify(
  1. AsyncValue<State> previousState,
  2. AsyncValue<State> newState
)
override

Called when a provider is rebuilt. Used for providers to not notify their listeners if the exposed value did not change.

Implementation

@override
bool updateShouldNotify(
  AsyncValue<State> previousState,
  AsyncValue<State> newState,
) {
  final wasLoading = previousState is AsyncLoading;
  final isLoading = newState is AsyncLoading;

  if (wasLoading || isLoading) return wasLoading != isLoading;

  return true;
}