1
0
Fork 0
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
thesis_shop/lib/bloc/product_bloc_states.dart

31 lines
934 B

part of 'product_bloc.dart';
abstract class ProductsState {
const ProductsState._();
const factory ProductsState.loading() = ProductsLoading;
const factory ProductsState.error(String errorMessage) = ProductsError;
const factory ProductsState.loaded(List<Product> products) = ProductsLoaded;
bool isLoading() => this is ProductsLoading;
bool isLoaded() => this is ProductsLoaded;
bool hasError() => this is ProductsError;
T as<T extends ProductsState>() => this as T;
List<Product> productsOrEmptyList() =>
isLoaded() ? as<ProductsLoaded>().products : [];
}
class ProductsLoading extends ProductsState {
const ProductsLoading() : super._();
}
class ProductsError extends ProductsState {
final String errorMessage;
const ProductsError(this.errorMessage) : super._();
}
class ProductsLoaded extends ProductsState {
final List<Product> products;
const ProductsLoaded(this.products) : super._();
}