audioUrl method

Future<String> audioUrl(
  1. String word
)

audioUrl is a class for making HTTP requests to the SOZLUK API using the word parameter and print word in the console.

Implementation

Future<String> audioUrl(String word) async {
  try {
    var res = await http.Client()
        .get(Uri.parse('https://sozluk.gov.tr/yazim?ara=$word'));
    var body = res.body;
    var decoded = jsonDecode(body);
    var json = decoded[0];
    var sozlukanlam = json["seskod"];
    print('Voice Code: $sozlukanlam');
    var anlamSesUrl = 'https://sozluk.gov.tr/ses/' + sozlukanlam + '.wav';
    return anlamSesUrl;
  } catch (e) {
    var hata = e.toString();
    if (hata.contains('NoSuchMethodError')) {
      var sozlukanlam =
          "ERR-003 - Couldn't find any audio files with this word.";
      return sozlukanlam;
    } else {
      var sozlukanlam = e.toString();
      return sozlukanlam;
    }
  }
}