feat: surface read-only load errors
This commit is contained in:
34
lib/app/load_state.dart
Normal file
34
lib/app/load_state.dart
Normal file
@@ -0,0 +1,34 @@
|
||||
enum LoadStatus { idle, loading, data, empty, error }
|
||||
|
||||
class LoadState<T> {
|
||||
final LoadStatus status;
|
||||
final T data;
|
||||
final String? errorMessage;
|
||||
|
||||
const LoadState.idle(this.data)
|
||||
: status = LoadStatus.idle,
|
||||
errorMessage = null;
|
||||
|
||||
const LoadState.loading(this.data)
|
||||
: status = LoadStatus.loading,
|
||||
errorMessage = null;
|
||||
|
||||
const LoadState.data(this.data)
|
||||
: status = LoadStatus.data,
|
||||
errorMessage = null;
|
||||
|
||||
const LoadState.empty(this.data)
|
||||
: status = LoadStatus.empty,
|
||||
errorMessage = null;
|
||||
|
||||
const LoadState.error(this.data, this.errorMessage)
|
||||
: status = LoadStatus.error;
|
||||
|
||||
bool get isIdle => status == LoadStatus.idle;
|
||||
|
||||
bool get isLoading => status == LoadStatus.loading;
|
||||
|
||||
bool get hasError => status == LoadStatus.error;
|
||||
|
||||
bool get isEmpty => status == LoadStatus.empty;
|
||||
}
|
||||
Reference in New Issue
Block a user