requireValue property

ValueT get requireValue

If hasValue is true, returns the value. Otherwise if hasError, rethrows the error. Finally if in loading state, throws a StateError.

This is typically used for when the UI assumes that value is always present.

Implementation

ValueT get requireValue {
  if (hasValue) return value as ValueT;
  if (hasError) {
    assert(this is! AsyncData, 'Bad state');
    throwProviderException(error!, stackTrace!);
  }

  assert(this is! AsyncData, 'Bad state');
  throw StateError(
    'Tried to call `requireValue` on an `AsyncValue` that has no value: $this',
  );
}