# TutorialFormBloc constructor Null safety

TutorialFormBloc(

1. String? appId,
2. {FormAction? formAction}

)

## Implementation

    TutorialFormBloc(this.appId, {this.formAction})
        : super(TutorialFormUninitialized()) {
      on<InitialiseNewTutorialFormEvent>((event, emit) {
        TutorialFormLoaded loaded = TutorialFormLoaded(
            value: TutorialModel(
          documentID: "",
          appId: "",
          name: "",
          title: "",
          description: "",
          tutorialEntries: [],
        ));
        emit(loaded);
      });

      on<InitialiseTutorialFormEvent>((event, emit) async {
        // Need to re-retrieve the document from the repository so that I get all associated types
        TutorialFormLoaded loaded = TutorialFormLoaded(
            value: await tutorialRepository(appId: appId)!
                .get(event.value!.documentID));
        emit(loaded);
      });
      on<InitialiseTutorialFormNoLoadEvent>((event, emit) async {
        TutorialFormLoaded loaded = TutorialFormLoaded(value: event.value);
        emit(loaded);
      });
      TutorialModel? newValue;
      on<ChangedTutorialDocumentID>((event, emit) async {
        if (state is TutorialFormInitialized) {
          final currentState = state as TutorialFormInitialized;
          newValue = currentState.value!.copyWith(documentID: event.value);
          if (formAction == FormAction.addAction) {
            emit(await _isDocumentIDValid(event.value, newValue!));
          } else {
            emit(SubmittableTutorialForm(value: newValue));
          }
        }
      });
      on<ChangedTutorialName>((event, emit) async {
        if (state is TutorialFormInitialized) {
          final currentState = state as TutorialFormInitialized;
          newValue = currentState.value!.copyWith(name: event.value);
          emit(SubmittableTutorialForm(value: newValue));
        }
      });
      on<ChangedTutorialTitle>((event, emit) async {
        if (state is TutorialFormInitialized) {
          final currentState = state as TutorialFormInitialized;
          newValue = currentState.value!.copyWith(title: event.value);
          emit(SubmittableTutorialForm(value: newValue));
        }
      });
      on<ChangedTutorialDescription>((event, emit) async {
        if (state is TutorialFormInitialized) {
          final currentState = state as TutorialFormInitialized;
          newValue = currentState.value!.copyWith(description: event.value);
          emit(SubmittableTutorialForm(value: newValue));
        }
      });
      on<ChangedTutorialTutorialEntries>((event, emit) async {
        if (state is TutorialFormInitialized) {
          final currentState = state as TutorialFormInitialized;
          newValue = currentState.value!.copyWith(tutorialEntries: event.value);
          emit(SubmittableTutorialForm(value: newValue));
        }
      });
      on<ChangedTutorialConditions>((event, emit) async {
        if (state is TutorialFormInitialized) {
          final currentState = state as TutorialFormInitialized;
          newValue = currentState.value!.copyWith(conditions: event.value);
          emit(SubmittableTutorialForm(value: newValue));
        }
      });
    }