claimTask method

Future<ApiResponseModel<ChallengeModel?>> claimTask({
  1. required String id,
  2. required String taskKey,
  3. required String companyId,
})

Claims XP reward for completing a task.

id is the ID of the challenge. taskKey is the key of the task to claim. companyId is the company ID. Returns the updated ChallengeModel instance.

Implementation

Future<ApiResponseModel<ChallengeModel?>> claimTask({
  required String id,
  required String taskKey,
  required String companyId,
}) async {
  final url = "$_baseUrl/challenges/$id/tasks/$taskKey/claim";

  final payload = {
    'apiKey': _apiKey,
    'companyId': companyId,
  };

  debugPrint("flutter_mon_sms_pro/challenges/claimTask/payload: $payload");

  final r = await _dio.post(url, data: payload);

  debugPrint("flutter_mon_sms_pro/challenges/claimTask/data: ${r.data}");

  final response = ApiResponseModel.fromJson(
    r.data,
    (data) => ChallengeModel.fromJson(data as Map<String, dynamic>),
  );

  return response;
}