Compare commits

...

3 Commits

5 changed files with 26 additions and 9 deletions

5
.gitignore vendored
View File

@ -244,7 +244,8 @@ app.*.map.json
/android/app/release
# Do not post secrets!
secrets.dart
lib/var/secrets.dart
# Keep locals local.
locals.dart
lib/var/local.dart
lib/var/config.dart

View File

@ -1,6 +1,6 @@
// Local
import '/var/secrets.dart';
import '/var/locals.dart';
import 'var/config.dart';
// Flutter / Dart
import 'package:flutter/material.dart';
@ -23,6 +23,9 @@ class MainApp extends StatefulWidget {
class _MainAppState extends State<MainApp> {
String weather = loadText;
bool keepLoading = false;
DateTime lastLoadTime = DateTime.now().subtract(
Duration(seconds: limitRefreshSeconds),
);
@override
void initState() {
@ -90,10 +93,10 @@ class _MainAppState extends State<MainApp> {
if (response.statusCode == 200) {
data = response.body;
var decodedData = jsonDecode(data);
if (debug) debugPrint(decodedData.toString());
//if (debug) debugPrint(decodedData.toString());
data = decodedData.toString();
} else {
debugPrint(response.statusCode.toString());
if (debug) debugPrint(response.statusCode.toString());
}
return data;
@ -104,7 +107,18 @@ class _MainAppState extends State<MainApp> {
}
_refreshWeather() {
var lastReloadSeconds = DateTime.now().difference(lastLoadTime).inSeconds;
if (debug) debugPrint("DEBUG: Refresh was $lastReloadSeconds seconds ago.");
if (lastReloadSeconds < limitRefreshSeconds) {
debugPrint("DEBUG: Skipping reload.");
// TODO / TBD: Show a toast / scaffold snackbar that it cannot reload yet,
// or change the button text to "Please wait X seconds!".
return;
}
weather = loadText;
_callOpenWeather();
lastLoadTime = DateTime.now();
}
}

View File

@ -0,0 +1,5 @@
// This file needs renamed `local.dart` when implemented.
// Project-wide configuration variables for both testing and production.
const bool debug = false;
const int limitRefreshSeconds = 60;

View File

@ -1,3 +0,0 @@
// This file needs renamed `local.dart` if implemented.
const bool debug = false;

View File

@ -1,3 +1,3 @@
// This file needs renamed `secrets.dart` and filled out properly if implemented.
final openWeatherKey = "abc123";
final String openWeatherKey = "abc123";