/// A generic sealed class that represents the state of an asynchronous operation. sealed class AsyncState { /// Base constructor for all asynchronous state variants. const AsyncState(); /// Represents an idle state before any asynchronous work has begun. const factory AsyncState.idle() = AsyncIdle; /// Represents an in-progress loading state. const factory AsyncState.loading() = AsyncLoading; /// Represents a completed asynchronous operation with a successful [value]. const factory AsyncState.loaded(T value) = AsyncLoaded; /// Represents a failed asynchronous operation with an [error]. const factory AsyncState.error(Object error) = AsyncError; } /// The idle state of an [AsyncState], indicating no active or completed work. /// /// Use this as the initial state before triggering an async operation. class AsyncIdle extends AsyncState { /// Creates an idle [AsyncState]. const AsyncIdle(); } /// The loading state of an [AsyncState], indicating that work is in progress. /// /// This state is typically used to show a loading spinner or progress indicator. class AsyncLoading extends AsyncState { /// Creates a loading [AsyncState]. const AsyncLoading(); } /// The success state of an [AsyncState], containing a completed [value]. /// /// This state indicates that the asynchronous work finished successfully. class AsyncLoaded extends AsyncState { /// The result of the successful asynchronous operation. final T value; /// Creates a loaded [AsyncState] with a [value]. const AsyncLoaded(this.value); } /// The error state of an [AsyncState], containing an [error]. /// /// This state indicates that the asynchronous work failed. class AsyncError extends AsyncState { /// The error produced during the asynchronous operation. final Object error; /// Creates an error [AsyncState] with an [error]. const AsyncError(this.error); }