Successfully pulling a good weather report. Now to add the heat index and wind chill calculations.
This commit is contained in:
@ -1,7 +1,10 @@
|
||||
// Local
|
||||
import 'dart:convert';
|
||||
|
||||
import '/var/secrets.dart';
|
||||
import '/var/config.dart';
|
||||
import 'helpers/http.dart';
|
||||
import 'helpers/json.dart';
|
||||
|
||||
// Flutter / Dart
|
||||
import 'package:flutter/material.dart';
|
||||
@ -74,10 +77,51 @@ class _MainAppState extends State<MainApp> {
|
||||
);
|
||||
}
|
||||
|
||||
// Call the
|
||||
// Convert the Future value into a usable value.
|
||||
pullWeather({
|
||||
String? country,
|
||||
String? zip,
|
||||
String? city,
|
||||
String? lat,
|
||||
String? long,
|
||||
}) async {
|
||||
country ??= "US";
|
||||
|
||||
if (lat != null && long != null) {
|
||||
weather = "Lat / Long Not Yet Implemented";
|
||||
} else if (zip != null) {
|
||||
weather = await hitOpenWeatherZip(zip, country);
|
||||
} else if (city != null) {
|
||||
weather = "City Weather Not Yet Implemented";
|
||||
} else {
|
||||
weather = "Please enter a location.";
|
||||
}
|
||||
|
||||
if (weather != loadText) {
|
||||
if (debug) {
|
||||
debugPrint("DEBUG: Formatting text.");
|
||||
}
|
||||
var weatherObject = jsonDecode(weather);
|
||||
|
||||
String weatherString = formatOpenWeatherData(weatherObject);
|
||||
|
||||
weather = weatherString;
|
||||
if (debug) {
|
||||
debugPrint("DEBUG: Set to formatted weather string.");
|
||||
}
|
||||
} else {
|
||||
if (debug) {
|
||||
debugPrint("DEBUG: Skipping text formatting.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Call the API and put the desired information into the screen variable.
|
||||
_refreshWeather() {
|
||||
var lastReloadSeconds = DateTime.now().difference(lastLoadTime).inSeconds;
|
||||
if (debug) debugPrint("DEBUG: Refresh was $lastReloadSeconds seconds ago.");
|
||||
if (debug) {
|
||||
debugPrint("DEBUG: Refresh was '$lastReloadSeconds' seconds ago.");
|
||||
}
|
||||
|
||||
if (lastReloadSeconds < limitRefreshSeconds) {
|
||||
debugPrint("DEBUG: Skipping reload.");
|
||||
@ -86,8 +130,14 @@ class _MainAppState extends State<MainApp> {
|
||||
return;
|
||||
}
|
||||
|
||||
if (debug) {
|
||||
debugPrint("DEBUG: Pulling weather...");
|
||||
}
|
||||
weather = loadText;
|
||||
weather = loadWeather();
|
||||
pullWeather(country: "US", zip: "47630");
|
||||
lastLoadTime = DateTime.now();
|
||||
if (debug) {
|
||||
debugPrint("DEBUG: Weather pulled and date is set.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user