# DynamicWidgetFormBloc constructor Null safety

DynamicWidgetFormBloc(

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

)

## Implementation

    DynamicWidgetFormBloc(this.appId, {this.formAction})
        : super(DynamicWidgetFormUninitialized()) {
      on<InitialiseNewDynamicWidgetFormEvent>((event, emit) {
        DynamicWidgetFormLoaded loaded = DynamicWidgetFormLoaded(
            value: DynamicWidgetModel(
          documentID: "",
          appId: "",
          description: "",
          content: "",
        ));
        emit(loaded);
      });

      on<InitialiseDynamicWidgetFormEvent>((event, emit) async {
        // Need to re-retrieve the document from the repository so that I get all associated types
        DynamicWidgetFormLoaded loaded = DynamicWidgetFormLoaded(
            value: await dynamicWidgetRepository(appId: appId)!
                .get(event.value!.documentID));
        emit(loaded);
      });
      on<InitialiseDynamicWidgetFormNoLoadEvent>((event, emit) async {
        DynamicWidgetFormLoaded loaded =
            DynamicWidgetFormLoaded(value: event.value);
        emit(loaded);
      });
      DynamicWidgetModel? newValue;
      on<ChangedDynamicWidgetDocumentID>((event, emit) async {
        if (state is DynamicWidgetFormInitialized) {
          final currentState = state as DynamicWidgetFormInitialized;
          newValue = currentState.value!.copyWith(documentID: event.value);
          if (formAction == FormAction.addAction) {
            emit(await _isDocumentIDValid(event.value, newValue!));
          } else {
            emit(SubmittableDynamicWidgetForm(value: newValue));
          }
        }
      });
      on<ChangedDynamicWidgetDescription>((event, emit) async {
        if (state is DynamicWidgetFormInitialized) {
          final currentState = state as DynamicWidgetFormInitialized;
          newValue = currentState.value!.copyWith(description: event.value);
          emit(SubmittableDynamicWidgetForm(value: newValue));
        }
      });
      on<ChangedDynamicWidgetContent>((event, emit) async {
        if (state is DynamicWidgetFormInitialized) {
          final currentState = state as DynamicWidgetFormInitialized;
          newValue = currentState.value!.copyWith(content: event.value);
          emit(SubmittableDynamicWidgetForm(value: newValue));
        }
      });
      on<ChangedDynamicWidgetBackground>((event, emit) async {
        if (state is DynamicWidgetFormInitialized) {
          final currentState = state as DynamicWidgetFormInitialized;
          newValue = currentState.value!.copyWith(background: event.value);
          emit(SubmittableDynamicWidgetForm(value: newValue));
        }
      });
      on<ChangedDynamicWidgetConditions>((event, emit) async {
        if (state is DynamicWidgetFormInitialized) {
          final currentState = state as DynamicWidgetFormInitialized;
          newValue = currentState.value!.copyWith(conditions: event.value);
          emit(SubmittableDynamicWidgetForm(value: newValue));
        }
      });
    }