valueOrNull property

T? valueOrNull

Return the value or previous value if in loading/error state.

If there is no previous value, null will be returned during loading/error state.

This is different from value, which will rethrow the error instead of returning null.

If you do not want to return previous value during loading/error states, consider using unwrapPrevious :

ref.watch(provider).unwrapPrevious()?.valueOrNull;

Implementation

T? get valueOrNull {
  if (hasValue) return value;
  return null;
}