19 lines
524 B
Dart
19 lines
524 B
Dart
class Resource<T> {
|
|
final T? data;
|
|
final bool isLoading;
|
|
final Exception? error;
|
|
|
|
Resource({this.data, this.isLoading = false, this.error});
|
|
|
|
static const _unset = Object();
|
|
|
|
Resource<T> copyWith({T? data, bool? isLoading, Object? error = _unset}) {
|
|
return Resource<T>(
|
|
data: data ?? this.data,
|
|
isLoading: isLoading ?? this.isLoading,
|
|
// Distinguish "not provided" from an explicit null to allow clearing error.
|
|
error: error == _unset ? this.error : error as Exception?,
|
|
);
|
|
}
|
|
}
|