feat: surface read-only load errors

This commit is contained in:
Artem Kokos
2026-04-23 20:01:37 +07:00
parent 504f65fc5f
commit 5d2d0ac4a7
7 changed files with 491 additions and 76 deletions

34
lib/app/load_state.dart Normal file
View 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;
}