Files
ignis_app/lib/app/load_state.dart
2026-04-23 20:02:59 +07:00

35 lines
830 B
Dart

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;
}