Implementation
static getTodayWeather(double x, double y) async {
DateTimeFormat dateInfo = baseTime(DateTime.now());
Map<String, String> parameter = {
"serviceKey": decodingKey,
"numOfRows": "300",
"pageNo": "1",
"base_date": dateInfo.date,
"base_time": dateInfo.time,
"nx": "55",
"ny": "127",
"dataType": "JSON",
};
String queryString = Uri(queryParameters: parameter).query;
print("queryString: $queryString");
String uri = endPoint + "?" + queryString;
print("uri: $uri");
Response response = await get(Uri.parse(uri));
String bodyString = utf8.decode(response.bodyBytes);
final Map<String, dynamic> data = await compute(_jsonDecode, bodyString);
final Map<String, dynamic> res = data['response'];
final Map<String, dynamic> body = res["body"];
final Map<String, dynamic> items = body["items"];
final List item = items["item"] as List;
final List<Weather> list = item.map((e) => Weather.fromJSON(e)).toList();
final Weather? tmp = list.where((element) => element.category == "TMP").first; // 1시간 기온
final Weather? sky = list.where((element) => element.category == "SKY").first; // 하늘상태
final Weather? tmn = list.where((element) => element.category == "TMN").first; // 일 최저기온
final Weather? tmx = list.where((element) => element.category == "TMX").first; // 일 최고기온
final Weather? pty = list.where((element) => element.category == "PTY").first; // 강수형태
print("tmp: $tmp");
print("sky: $sky");
print("tmn: $tmn");
print("tmx: $tmx");
print("pty: $pty");
print("weather: ${skyState(sky!.fcstValue, pty!.fcstValue)}, 현재기온: ${tmp?.fcstValue}, 최저기온: ${tmn?.fcstValue}, 최고기온: ${tmx?.fcstValue}");
}