translate method

Future<String?> translate(
  1. BuildContext context,
  2. String source,
  3. String? inputLanCode,
  4. String outputLanCode,
  5. String type,
  6. String apiKey,
  7. String token,
)

Implementation

Future<String?> translate(
    BuildContext context,
    String source,
    String? inputLanCode,
    String outputLanCode,
    String type,
    String apiKey,
    String token) async {
  final body = jsonEncode({
    "q": source,
    "source": inputLanCode,
    "target": outputLanCode,
    "format": type,
    "key": apiKey,
  });
  var res = await NetworkCalls().call(
      body,
      context,
      "https://translation.googleapis.com/language/translate/v2?key=" +
          apiKey,
      token);
  var response = TranslateResponse.fromJson(res);
  return response.data!.translations![0].translatedText;
}