map<NewT> method
NewT
map<NewT>({
- required NewT data(
- AsyncData<
ValueT> data
- AsyncData<
- required NewT error(
- AsyncError<
ValueT> error
- AsyncError<
- required NewT loading(
- AsyncLoading<
ValueT> loading
- AsyncLoading<
Perform some action based on the current state of the AsyncValue.
This allows reading the content of an AsyncValue in a type-safe way, without potentially ignoring to handle a case.
Implementation
NewT map<NewT>({
required NewT Function(AsyncData<ValueT> data) data,
required NewT Function(AsyncError<ValueT> error) error,
required NewT Function(AsyncLoading<ValueT> loading) loading,
}) {
final that = this;
switch (that) {
case AsyncLoading():
return loading(that);
case AsyncData():
return data(that);
case AsyncError():
return error(that);
}
}