WorkflowCreateBloc constructor

WorkflowCreateBloc(
  1. String appId,
  2. WorkflowModel initialiseWithWorkflowModel,
  3. VoidCallback? callOnAction
)

Implementation

WorkflowCreateBloc(
    this.appId, WorkflowModel initialiseWithWorkflowModel, this.callOnAction)
    : workflowModel = deepCopy(initialiseWithWorkflowModel),
      super(WorkflowCreateUninitialised()) {
  on<WorkflowCreateEventValidateEvent>((event, emit) {
    emit(WorkflowCreateValidated(deepCopy(event.workflowModel)));
  });

  on<WorkflowCreateEventApplyChanges>((event, emit) async {
    var theState = state as WorkflowCreateInitialised;
    workflowModel.name = theState.workflowModel.name;
    workflowModel.workflowTask = theState.workflowModel.workflowTask;
    if (event.save) {
      var wf = await workflowRepository(appId: appId)!
          .get(theState.workflowModel.documentID);
      if (wf == null) {
        await workflowRepository(appId: appId)!.add(theState.workflowModel);
      } else {
        await workflowRepository(appId: appId)!
            .update(theState.workflowModel);
      }
    }

    if (callOnAction != null) {
      callOnAction!();
    }
  });
}