finishTask method

Future<void> finishTask(
  1. AppModel app,
  2. BuildContext context,
  3. AssignmentModel assignmentModel,
  4. ExecutionResults executionResult,
  5. String? feedback,
)

Implementation

Future<void> finishTask(
    AppModel app,
    BuildContext context,
    AssignmentModel assignmentModel,
    ExecutionResults executionResult,
    String? feedback) async {
  var state = AccessBloc.getState(context);
  if (state is AccessDetermined) {
    await _handleCurrentAssignment(
        context, assignmentModel, _isNewAssignment, executionResult);
    if (state.getMember() != null) {
      var member = state.getMember();
      if (member != null) {
        if (executionResult.status == ExecutionStatus.success) {
          await _sendMessage(
              app.documentID,
              member.documentID,
              assignmentModel.confirmMessage,
              app,
              member,
              assignmentModel,
              feedback);
          var nextAssignment = await _nextAssignment(
              context, assignmentModel, executionResult, member, app);
          if (nextAssignment != null) {
            // if the next assignment is assigned to the currently logged in member, then present it instantly:
            MemberModel? currentMember =
                AccessBloc.getState(context).getMember();
            if ((currentMember != null) &&
                (nextAssignment.assigneeId == currentMember.documentID) &&
                nextAssignment.task!.executeInstantly) {
              nextAssignment.task!.callExecute(app, context,
                  currentMember.documentID, nextAssignment, false,
                  finaliseWorkflow: _finaliseWorkflow);
            }
          }
        } else {
          await _sendMessage(
              app.documentID,
              member.documentID,
              assignmentModel.rejectMessage,
              app,
              member,
              assignmentModel,
              feedback);
        }
      }
    }
  }
  if ((_finaliseWorkflow != null)) {
    _finaliseWorkflow!(context,
        executionResult.status == ExecutionStatus.success, assignmentModel);
  }
}