SimpleTextFormBloc constructor Null safety

SimpleTextFormBloc(
  1. String? appId,
  2. {FormAction? formAction}
)

Implementation

SimpleTextFormBloc(this.appId, {this.formAction})
    : super(SimpleTextFormUninitialized()) {
  on<InitialiseNewSimpleTextFormEvent>((event, emit) {
    SimpleTextFormLoaded loaded = SimpleTextFormLoaded(
        value: SimpleTextModel(
      documentID: "",
      appId: "",
      description: "",
      title: "",
      text: "",
    ));
    emit(loaded);
  });

  on<InitialiseSimpleTextFormEvent>((event, emit) async {
    // Need to re-retrieve the document from the repository so that I get all associated types
    SimpleTextFormLoaded loaded = SimpleTextFormLoaded(
        value: await simpleTextRepository(appId: appId)!
            .get(event.value!.documentID));
    emit(loaded);
  });
  on<InitialiseSimpleTextFormNoLoadEvent>((event, emit) async {
    SimpleTextFormLoaded loaded = SimpleTextFormLoaded(value: event.value);
    emit(loaded);
  });
  SimpleTextModel? newValue;
  on<ChangedSimpleTextDocumentID>((event, emit) async {
    if (state is SimpleTextFormInitialized) {
      final currentState = state as SimpleTextFormInitialized;
      newValue = currentState.value!.copyWith(documentID: event.value);
      if (formAction == FormAction.addAction) {
        emit(await _isDocumentIDValid(event.value, newValue!));
      } else {
        emit(SubmittableSimpleTextForm(value: newValue));
      }
    }
  });
  on<ChangedSimpleTextDescription>((event, emit) async {
    if (state is SimpleTextFormInitialized) {
      final currentState = state as SimpleTextFormInitialized;
      newValue = currentState.value!.copyWith(description: event.value);
      emit(SubmittableSimpleTextForm(value: newValue));
    }
  });
  on<ChangedSimpleTextTitle>((event, emit) async {
    if (state is SimpleTextFormInitialized) {
      final currentState = state as SimpleTextFormInitialized;
      newValue = currentState.value!.copyWith(title: event.value);
      emit(SubmittableSimpleTextForm(value: newValue));
    }
  });
  on<ChangedSimpleTextText>((event, emit) async {
    if (state is SimpleTextFormInitialized) {
      final currentState = state as SimpleTextFormInitialized;
      newValue = currentState.value!.copyWith(text: event.value);
      emit(SubmittableSimpleTextForm(value: newValue));
    }
  });
  on<ChangedSimpleTextConditions>((event, emit) async {
    if (state is SimpleTextFormInitialized) {
      final currentState = state as SimpleTextFormInitialized;
      newValue = currentState.value!.copyWith(conditions: event.value);
      emit(SubmittableSimpleTextForm(value: newValue));
    }
  });
  on<ChangedSimpleTextTextAlign>((event, emit) async {
    if (state is SimpleTextFormInitialized) {
      final currentState = state as SimpleTextFormInitialized;
      newValue = currentState.value!.copyWith(textAlign: event.value);
      emit(SubmittableSimpleTextForm(value: newValue));
    }
  });
}