repoFunction method

String repoFunction(
  1. String functionName, {
  2. String repoParameter = '',
  3. String requestType = 'get',
  4. String url = "ApiConstants.todosApiUrl",
})

Implementation

String repoFunction(String functionName,
    {String repoParameter = '',
      String requestType = 'get',
      String url = "ApiConstants.todosApiUrl"}) {
  functionName = functionName.toCamelCaseFirstLetterForEachWord();

  String newRepoParameter =
  repoParameter.split(" ")[0].toCamelCaseFirstLetterForEachWord();
  newRepoParameter += repoParameter.isNotEmpty ? " ${repoParameter.split(" ").last}" : "";

  return """
Future<ApiResult> ${url.split("/").last.replaceAll("ApiConstants.", "").toCamelCaseFirstLetterForEachWord()}($newRepoParameter) async {
  ApiResult apiResult = ApiResult();
  try {
    apiResult = await dioHelper.safeApiCall(
      $url,
      ${SetupRequestData.getRequestType(requestType)},
    );
    apiResult.apiCallStatus = ApiCallStatus.success;

    return apiResult;
  } catch (e) {
    return ApiResult.error(apiCallStatus: ApiCallStatus.error);
  }
}
""";
}