GridFormBloc constructor Null safety

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

Implementation

GridFormBloc(this.appId, {this.formAction}) : super(GridFormUninitialized()) {
  on<InitialiseNewGridFormEvent>((event, emit) {
    GridFormLoaded loaded = GridFormLoaded(
        value: GridModel(
      documentID: "",
      appId: "",
      description: "",
      bodyComponents: [],
    ));
    emit(loaded);
  });

  on<InitialiseGridFormEvent>((event, emit) async {
    // Need to re-retrieve the document from the repository so that I get all associated types
    GridFormLoaded loaded = GridFormLoaded(
        value:
            await gridRepository(appId: appId)!.get(event.value!.documentID));
    emit(loaded);
  });
  on<InitialiseGridFormNoLoadEvent>((event, emit) async {
    GridFormLoaded loaded = GridFormLoaded(value: event.value);
    emit(loaded);
  });
  GridModel? newValue;
  on<ChangedGridDocumentID>((event, emit) async {
    if (state is GridFormInitialized) {
      final currentState = state as GridFormInitialized;
      newValue = currentState.value!.copyWith(documentID: event.value);
      if (formAction == FormAction.addAction) {
        emit(await _isDocumentIDValid(event.value, newValue!));
      } else {
        emit(SubmittableGridForm(value: newValue));
      }
    }
  });
  on<ChangedGridDescription>((event, emit) async {
    if (state is GridFormInitialized) {
      final currentState = state as GridFormInitialized;
      newValue = currentState.value!.copyWith(description: event.value);
      emit(SubmittableGridForm(value: newValue));
    }
  });
  on<ChangedGridBodyComponents>((event, emit) async {
    if (state is GridFormInitialized) {
      final currentState = state as GridFormInitialized;
      newValue = currentState.value!.copyWith(bodyComponents: event.value);
      emit(SubmittableGridForm(value: newValue));
    }
  });
  on<ChangedGridGridView>((event, emit) async {
    if (state is GridFormInitialized) {
      final currentState = state as GridFormInitialized;
      if (event.value != null) {
        newValue = currentState.value!.copyWith(
            gridView:
                await gridViewRepository(appId: appId)!.get(event.value));
      }
      emit(SubmittableGridForm(value: newValue));
    }
  });
  on<ChangedGridConditions>((event, emit) async {
    if (state is GridFormInitialized) {
      final currentState = state as GridFormInitialized;
      newValue = currentState.value!.copyWith(conditions: event.value);
      emit(SubmittableGridForm(value: newValue));
    }
  });
}