getJson method
getJson is a class for making HTTP requests to the SOZLUK API using the word
parameter.
Implementation
Future<String> getJson(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;
return sozlukanlam.toString();
} catch (e) {
var hata = e.toString();
if (hata.contains('NoSuchMethodError')) {
var sozlukanlam = "ERR-004 - Couldn't find any json with this word.";
return sozlukanlam;
} else {
var sozlukanlam = e.toString();
return sozlukanlam;
}
}
}