Skip to content
Snippets Groups Projects
Commit 04a9d20e authored by Sara Savanovic Djordjevic's avatar Sara Savanovic Djordjevic
Browse files

update: attempt at snackBar alert, not tested

parent d529f3d0
No related branches found
No related tags found
2 merge requests!9Clhp map,!8Clhp map
...@@ -23,6 +23,8 @@ class _DefaultPageState extends State<DefaultPage> { ...@@ -23,6 +23,8 @@ class _DefaultPageState extends State<DefaultPage> {
late Future<List<Measurement>> markerListFuture; late Future<List<Measurement>> markerListFuture;
late Future<Uint8List> relationFuture; late Future<Uint8List> relationFuture;
/// Fetch measurement and relation data, check server connection, and
/// start a request timer
@override @override
void initState() { void initState() {
super.initState(); super.initState();
...@@ -37,9 +39,11 @@ class _DefaultPageState extends State<DefaultPage> { ...@@ -37,9 +39,11 @@ class _DefaultPageState extends State<DefaultPage> {
throw Exception("Failed to fetch measurements: $error"); throw Exception("Failed to fetch measurements: $error");
}); });
if (!serverConnection) {
_showConnectionMessage();
}
relationFuture = fetchRelation(); relationFuture = fetchRelation();
//relationFuture = Future.value(Uint8List(0));
// Schedule fetchMarkerData to run periodically based on fetchInterval from consts // Schedule fetchMarkerData to run periodically based on fetchInterval from consts
const Duration interval = Duration(minutes: fetchInterval); // NB fetchInterval value to be determined const Duration interval = Duration(minutes: fetchInterval); // NB fetchInterval value to be determined
...@@ -48,7 +52,17 @@ class _DefaultPageState extends State<DefaultPage> { ...@@ -48,7 +52,17 @@ class _DefaultPageState extends State<DefaultPage> {
}); });
} }
// Fetch-interval timer /// Display a message for 5 seconds informing the user
/// of lacking server connection
void _showConnectionMessage() {
const snackBar = SnackBar(
content: Text('Failed to connect to the server. Information about'
'ice safety could be outdated!'),
duration: Duration(seconds: 5),
);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
}
/// Timer for resending requests to server
@override @override
void dispose() { void dispose() {
// Cancel timer on widget termination // Cancel timer on widget termination
...@@ -93,8 +107,8 @@ class _DefaultPageState extends State<DefaultPage> { ...@@ -93,8 +107,8 @@ class _DefaultPageState extends State<DefaultPage> {
} else if (snapshot.hasError) { } else if (snapshot.hasError) {
return Center(child: Text('Error: ${snapshot.error}')); return Center(child: Text('Error: ${snapshot.error}'));
} else { } else {
if (!serverConnection) { // NB: implement alert if (!serverConnection) { // NB: implement dialogue box
print("Failed to connect to server"); print("Failed to connect to server"); // Here...
} }
// Display default page once all data is loaded from server // Display default page once all data is loaded from server
List<Measurement> markerList = snapshot.data![0] as List<Measurement>; List<Measurement> markerList = snapshot.data![0] as List<Measurement>;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment