initialStateFor<K extends Object, V> static method
ResourceState<K, V>
initialStateFor<K extends Object, V>(
- K? key,
- InitialValue<
K, V> ? initialValue, { - required bool isLoading,
Implementation
static ResourceState<K, V> initialStateFor<K extends Object, V>(
K? key,
InitialValue<K, V>? initialValue, {
required bool isLoading,
}) {
if (key != null) {
final value = () {
try {
return initialValue?.call(key);
} catch (e, s) {
assert(() {
print('WARN: Initial value callback threw on key \'$key\'. '
'Ignoring initial value. Error: $e');
print(s);
return true;
}());
return null;
}
}();
if (value != null) {
return ResourceState.withValue(key, value,
isLoading: isLoading, source: Source.cache);
}
}
return ResourceState.initial(key, isLoading: isLoading);
}