whenData<NewT> method
Shorthand for when to handle only the data
case.
For loading/error cases, creates a new AsyncValue with the corresponding generic type while preserving the error/stacktrace.
Implementation
AsyncValue<NewT> whenData<NewT>(NewT Function(ValueT value) cb) {
return map(
data: (d) {
try {
return AsyncData._(
(cb(d.value), kind: null, source: null),
loading: d._loading,
error: d._error,
);
} catch (err, stack) {
return AsyncError._(
(err: err, stack: stack, retrying: null),
loading: d._loading,
value: null,
);
}
},
error: (e) => AsyncError._(e._error, loading: e._loading, value: null),
loading: (l) => AsyncLoading<NewT>(progress: progress),
);
}