# DividerFormBloc constructor Null safety

DividerFormBloc(

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

)

## Implementation

    DividerFormBloc(this.appId, {this.formAction})
        : super(DividerFormUninitialized()) {
      on<InitialiseNewDividerFormEvent>((event, emit) {
        DividerFormLoaded loaded = DividerFormLoaded(
            value: DividerModel(
          documentID: "",
          appId: "",
          description: "",
          color: RgbModel(r: 255, g: 0, b: 0, opacity: 1.00),
          height: 0.0,
          thickness: 0.0,
          indent: 0.0,
          endIndent: 0.0,
        ));
        emit(loaded);
      });

      on<InitialiseDividerFormEvent>((event, emit) async {
        // Need to re-retrieve the document from the repository so that I get all associated types
        DividerFormLoaded loaded = DividerFormLoaded(
            value: await dividerRepository(appId: appId)!
                .get(event.value!.documentID));
        emit(loaded);
      });
      on<InitialiseDividerFormNoLoadEvent>((event, emit) async {
        DividerFormLoaded loaded = DividerFormLoaded(value: event.value);
        emit(loaded);
      });
      DividerModel? newValue;
      on<ChangedDividerDocumentID>((event, emit) async {
        if (state is DividerFormInitialized) {
          final currentState = state as DividerFormInitialized;
          newValue = currentState.value!.copyWith(documentID: event.value);
          if (formAction == FormAction.addAction) {
            emit(await _isDocumentIDValid(event.value, newValue!));
          } else {
            emit(SubmittableDividerForm(value: newValue));
          }
        }
      });
      on<ChangedDividerDescription>((event, emit) async {
        if (state is DividerFormInitialized) {
          final currentState = state as DividerFormInitialized;
          newValue = currentState.value!.copyWith(description: event.value);
          emit(SubmittableDividerForm(value: newValue));
        }
      });
      on<ChangedDividerColor>((event, emit) async {
        if (state is DividerFormInitialized) {
          final currentState = state as DividerFormInitialized;
          newValue = currentState.value!.copyWith(color: event.value);
          emit(SubmittableDividerForm(value: newValue));
        }
      });
      on<ChangedDividerHeight>((event, emit) async {
        if (state is DividerFormInitialized) {
          final currentState = state as DividerFormInitialized;
          if (isDouble(event.value!)) {
            newValue =
                currentState.value!.copyWith(height: double.parse(event.value!));
            emit(SubmittableDividerForm(value: newValue));
          } else {
            newValue = currentState.value!.copyWith(height: 0.0);
            emit(HeightDividerFormError(
                message: "Value should be a number or decimal number",
                value: newValue));
          }
        }
      });
      on<ChangedDividerThickness>((event, emit) async {
        if (state is DividerFormInitialized) {
          final currentState = state as DividerFormInitialized;
          if (isDouble(event.value!)) {
            newValue = currentState.value!
                .copyWith(thickness: double.parse(event.value!));
            emit(SubmittableDividerForm(value: newValue));
          } else {
            newValue = currentState.value!.copyWith(thickness: 0.0);
            emit(ThicknessDividerFormError(
                message: "Value should be a number or decimal number",
                value: newValue));
          }
        }
      });
      on<ChangedDividerIndent>((event, emit) async {
        if (state is DividerFormInitialized) {
          final currentState = state as DividerFormInitialized;
          if (isDouble(event.value!)) {
            newValue =
                currentState.value!.copyWith(indent: double.parse(event.value!));
            emit(SubmittableDividerForm(value: newValue));
          } else {
            newValue = currentState.value!.copyWith(indent: 0.0);
            emit(IndentDividerFormError(
                message: "Value should be a number or decimal number",
                value: newValue));
          }
        }
      });
      on<ChangedDividerEndIndent>((event, emit) async {
        if (state is DividerFormInitialized) {
          final currentState = state as DividerFormInitialized;
          if (isDouble(event.value!)) {
            newValue = currentState.value!
                .copyWith(endIndent: double.parse(event.value!));
            emit(SubmittableDividerForm(value: newValue));
          } else {
            newValue = currentState.value!.copyWith(endIndent: 0.0);
            emit(EndIndentDividerFormError(
                message: "Value should be a number or decimal number",
                value: newValue));
          }
        }
      });
      on<ChangedDividerConditions>((event, emit) async {
        if (state is DividerFormInitialized) {
          final currentState = state as DividerFormInitialized;
          newValue = currentState.value!.copyWith(conditions: event.value);
          emit(SubmittableDividerForm(value: newValue));
        }
      });
    }