Compare commits
3 Commits
0f475773de
...
8c8b848090
Author | SHA1 | Date | |
---|---|---|---|
8c8b848090 | |||
54ae255e9e | |||
7a48d137e0 |
5
.gitignore
vendored
5
.gitignore
vendored
@ -244,7 +244,8 @@ app.*.map.json
|
|||||||
/android/app/release
|
/android/app/release
|
||||||
|
|
||||||
# Do not post secrets!
|
# Do not post secrets!
|
||||||
secrets.dart
|
lib/var/secrets.dart
|
||||||
|
|
||||||
# Keep locals local.
|
# Keep locals local.
|
||||||
locals.dart
|
lib/var/local.dart
|
||||||
|
lib/var/config.dart
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// Local
|
// Local
|
||||||
import '/var/secrets.dart';
|
import '/var/secrets.dart';
|
||||||
import '/var/locals.dart';
|
import 'var/config.dart';
|
||||||
|
|
||||||
// Flutter / Dart
|
// Flutter / Dart
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@ -23,6 +23,9 @@ class MainApp extends StatefulWidget {
|
|||||||
class _MainAppState extends State<MainApp> {
|
class _MainAppState extends State<MainApp> {
|
||||||
String weather = loadText;
|
String weather = loadText;
|
||||||
bool keepLoading = false;
|
bool keepLoading = false;
|
||||||
|
DateTime lastLoadTime = DateTime.now().subtract(
|
||||||
|
Duration(seconds: limitRefreshSeconds),
|
||||||
|
);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@ -90,10 +93,10 @@ class _MainAppState extends State<MainApp> {
|
|||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
data = response.body;
|
data = response.body;
|
||||||
var decodedData = jsonDecode(data);
|
var decodedData = jsonDecode(data);
|
||||||
if (debug) debugPrint(decodedData.toString());
|
//if (debug) debugPrint(decodedData.toString());
|
||||||
data = decodedData.toString();
|
data = decodedData.toString();
|
||||||
} else {
|
} else {
|
||||||
debugPrint(response.statusCode.toString());
|
if (debug) debugPrint(response.statusCode.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
@ -104,7 +107,18 @@ class _MainAppState extends State<MainApp> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_refreshWeather() {
|
_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;
|
weather = loadText;
|
||||||
_callOpenWeather();
|
_callOpenWeather();
|
||||||
|
lastLoadTime = DateTime.now();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
5
lib/var/config.EXAMPLE.dart
Normal file
5
lib/var/config.EXAMPLE.dart
Normal 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;
|
@ -1,3 +0,0 @@
|
|||||||
// This file needs renamed `local.dart` if implemented.
|
|
||||||
|
|
||||||
const bool debug = false;
|
|
@ -1,3 +1,3 @@
|
|||||||
// This file needs renamed `secrets.dart` and filled out properly if implemented.
|
// This file needs renamed `secrets.dart` and filled out properly if implemented.
|
||||||
|
|
||||||
final openWeatherKey = "abc123";
|
final String openWeatherKey = "abc123";
|
Reference in New Issue
Block a user