mapEventToState method

  1. @override
Stream<FastPlanBlocState> mapEventToState(
  1. FastPlanBlocEvent event
)
override

Must be implemented when a class extends BidirectionalBloc. mapEventToState is called whenever an event is added and will convert that event into a new BloC state. It can yield zero, one or several states for an event.

Implementation

@override
Stream<FastPlanBlocState> mapEventToState(FastPlanBlocEvent event) async* {
  final payload = event.payload;

  if (payload is FastPlanBlocEventPayload && payload.productId != null) {
    final productId = payload.productId!;
    final type = event.type;
    final error = event.error;

    if (type == FastPlanBlocEventType.purchasePlan) {
      yield* handlePurchasePlanEvent(productId);
    } else if (type == FastPlanBlocEventType.planPurchased) {
      yield* handlePlanPurchasedEvent(productId);
    } else if (type == FastPlanBlocEventType.purchasePlanFailed) {
      yield* handlePurchasePlanFailedEvent(productId, error);
    } else if (type == FastPlanBlocEventType.purchasePlanCanceled) {
      yield* handlePurchasePlanCanceledEvent(productId);
    } else if (type == FastPlanBlocEventType.restorePlan) {
      yield* handleRestorePlanEvent(productId);
    } else if (type == FastPlanBlocEventType.planRestored) {
      yield* handlePlanRestoredEvent(productId);
    } else if (type == FastPlanBlocEventType.restorePlanFailed) {
      yield* handleRestorePlanFailedEvent(productId, error);
    } else if (type == FastPlanBlocEventType.resetError) {
      yield* handleResetErrorEvent();
    }
  }
}