proverb method

Future<String> proverb(
  1. String word
)

proverb is a class for making HTTP requests to the SOZLUK API using the word parameter.

Implementation

Future<String> proverb(String word) async {
  try {
    var res = await http.Client()
        .get(Uri.parse('https://sozluk.gov.tr/gts?ara=$word'));
    var body = res.body;
    var decoded = jsonDecode(body);
    var json = decoded[0];
    var sozlukanlam = json["atasozu"][0]["madde"];
    return sozlukanlam;
  } catch (e) {
    var hata = e.toString();
    if (hata.contains('NoSuchMethodError')) {
      var sozlukanlam = "ERR-002 - Couldn't find any proverb with this word.";
      return sozlukanlam;
    } else {
      var sozlukanlam = e.toString();
      return sozlukanlam;
    }
  }
}