requireState property
- @internal
Read the current value of a provider and:
- if in error state, rethrow the error
- if the provider is not initialized, gracefully handle the error.
This is not meant for public consumption. Instead, public API should use readSelf.
Implementation
@internal
StateT get requireState {
assert(
() {
if (debugAssertDidSetStateEnabled && !_debugDidSetState) {
throw StateError(
'Tried to read the state of an uninitialized provider',
);
}
return true;
}(),
'',
);
final state = getState();
if (state == null) {
throw StateError('Tried to read the state of an uninitialized provider');
}
return state.when(
error: throwErrorWithCombinedStackTrace,
data: (data) => data,
);
}