NewAppCreateBloc constructor

NewAppCreateBloc()

Implementation

NewAppCreateBloc() : super(NewAppCreateUninitialised()) {
  on<NewAppCreateEventInitialise>((event, emit) {
    var appToBeCreated = AppModel(
        documentID: event.initialAppIdToBeCreated,
        appStatus: AppStatus.offline,
        ownerID: event.member.documentID);
    emit(NewAppCreateAllowEnterDetails(appToBeCreated, event.member));
  });

  on<NewAppCreateConfirm>((event, emit) async {
    var theState = state as NewAppCreateInitialised;
    var appId = theState.appToBeCreated.documentID;
    var app = await appRepository()!.get(appId);
    if (app == null) {
      add(NewAppCreateProgressed(0));
      AppBuilder(
        theState.appToBeCreated,
        event.loggedIn.member,
      ).create(
          NewAppCreateBlocConsomeAppBuilderProgress(newAppCreateBloc: this),
          event.fromExisting,
          memberMediumModel: event.memberMediumModel,
          url: event.url);
    } else {
      emit(NewAppCreateError(theState.appToBeCreated, theState.member,
          'App with ID $appId already exists. Choose a unique identifier'));
    }
  });

  on<NewAppSwitchAppEvent>((event, emit) {
    var theState = state as NewAppCreateInitialised;
    emit(SwitchApp(theState.appToBeCreated, theState.member));
  });

  on<NewAppCreateProgressed>((event, emit) {
    var theState = state as NewAppCreateInitialised;
    emit(NewAppCreateCreateInProgress(
        theState.appToBeCreated, theState.member, event.progress));
  });

  on<NewAppCancelled>((event, emit) {
    var theState = state as NewAppCreateInitialised;
    emit(NewAppCreateCreateCancelled(
      theState.appToBeCreated,
      theState.member,
    ));
  });
}