# BookletFormBloc constructor Null safety

BookletFormBloc(

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

)

## Implementation

    BookletFormBloc(this.appId, {this.formAction})
        : super(BookletFormUninitialized()) {
      on<InitialiseNewBookletFormEvent>((event, emit) {
        BookletFormLoaded loaded = BookletFormLoaded(
            value: BookletModel(
          documentID: "",
          appId: "",
          description: "",
          sections: [],
        ));
        emit(loaded);
      });

      on<InitialiseBookletFormEvent>((event, emit) async {
        // Need to re-retrieve the document from the repository so that I get all associated types
        BookletFormLoaded loaded = BookletFormLoaded(
            value: await bookletRepository(appId: appId)!
                .get(event.value!.documentID));
        emit(loaded);
      });
      on<InitialiseBookletFormNoLoadEvent>((event, emit) async {
        BookletFormLoaded loaded = BookletFormLoaded(value: event.value);
        emit(loaded);
      });
      BookletModel? newValue;
      on<ChangedBookletDocumentID>((event, emit) async {
        if (state is BookletFormInitialized) {
          final currentState = state as BookletFormInitialized;
          newValue = currentState.value!.copyWith(documentID: event.value);
          if (formAction == FormAction.addAction) {
            emit(await _isDocumentIDValid(event.value, newValue!));
          } else {
            emit(SubmittableBookletForm(value: newValue));
          }
        }
      });
      on<ChangedBookletDescription>((event, emit) async {
        if (state is BookletFormInitialized) {
          final currentState = state as BookletFormInitialized;
          newValue = currentState.value!.copyWith(description: event.value);
          emit(SubmittableBookletForm(value: newValue));
        }
      });
      on<ChangedBookletSections>((event, emit) async {
        if (state is BookletFormInitialized) {
          final currentState = state as BookletFormInitialized;
          newValue = currentState.value!.copyWith(sections: event.value);
          emit(SubmittableBookletForm(value: newValue));
        }
      });
      on<ChangedBookletConditions>((event, emit) async {
        if (state is BookletFormInitialized) {
          final currentState = state as BookletFormInitialized;
          newValue = currentState.value!.copyWith(conditions: event.value);
          emit(SubmittableBookletForm(value: newValue));
        }
      });
    }