fetchSingleTranslation function

Future fetchSingleTranslation(
  1. dynamic sourceText,
  2. dynamic targetLocale
)

Implementation

Future fetchSingleTranslation(sourceText, targetLocale) {
  totalPendingRequests++;

  return http
      .post(
    Uri.parse(_reqUrl + '/' + targetLocale),
    body: {
      'en': sourceText,
      'target': targetLocale,
    },
    headers: _reqHeaders,
  )
      .then((res) {
    String hash = md5.convert(utf8.encode(sourceText)).toString();

    Map body = jsonDecode(utf8.decode(res.bodyBytes));

    globalTranslations[hash] = body[targetLocale];
    // print('\nfetched data of ' + text);
    // print(res[targetLocale]);

    totalPendingRequests--;

    return body[targetLocale];
  });
}