toData method
Attempts to convert the result to Data.
The provided data
will be used, if specified, otherwise the existing data will be used if possible. If no data
is present, the orElse
callback will be used, if provided, to produce fallback data. In case of a failure to
produce data, the value will be set to Error.noData.
Implementation
Result<T> toData({T? data, T Function()? orElse, DateTime? lastUpdate}) {
if (hasData || data != null || orElse != null) {
return Data(
data ?? this.data ?? orElse!.call(),
lastUpdate: lastUpdate ?? DateTime.now(),
);
} else {
return Error.noData(lastUpdate: lastUpdate);
}
}