mapEventToState method
Maps incoming FastStoreBlocEvents to the appropriate state changes based on the event type.
Implementation
@override
Stream<FastStoreBlocState> mapEventToState(
FastStoreBlocEvent event,
) async* {
final payload = event.payload;
final type = event.type;
final error = event.error;
if (type == FastStoreBlocEventType.init) {
if (payload is FastStoreBlocPayload) {
yield* handleInitEvent(payload);
}
} else if (type == FastStoreBlocEventType.initialized) {
yield* handleInitializedEvent();
} else if (isInitialized) {
if (_isStoreAvailable) {
switch (type) {
// Restore purchases
case FastStoreBlocEventType.restorePurchases:
yield* handleRestorePurchasesEvent();
case FastStoreBlocEventType.purchaseRestored:
if (payload is FastStoreBlocPayload) {
yield* handlePurchasesRestoredEvent(payload);
}
case FastStoreBlocEventType.restorePurchasesFailed:
yield* handleRestorePurchasesFailedEvent(error);
// Load products
case FastStoreBlocEventType.loadProducts:
yield* handleLoadProductsEvent();
case FastStoreBlocEventType.productsLoaded:
if (payload is FastStoreBlocPayload) {
yield* handleProductsLoadedEvent(payload);
}
case FastStoreBlocEventType.loadProductsFailed:
yield* handleLoadProductsFailedEvent(error);
// Purchase product
case FastStoreBlocEventType.purchaseProduct:
if (payload is FastStoreBlocPayload) {
yield* handlePurchaseProductEvent(payload);
}
case FastStoreBlocEventType.purchaseProductFailed:
yield* handlePurchaseProductFailedEvent(error);
case FastStoreBlocEventType.productPurchased:
if (payload is FastStoreBlocPayload) {
yield* handleProductPurchasedEvent(payload);
}
case FastStoreBlocEventType.purchaseProductCanceled:
yield* handlePurchaseProductCanceledEvent();
default:
assert(false, 'FastStoreBloc is not initialized yet.');
}
}
} else {
assert(false, 'FastAppInfoBloc is not initialized yet.');
}
}