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

add: network_controller.dart

parent b780309d
No related branches found
No related tags found
1 merge request!11Clhp map
import 'package:get/get.dart';
import 'package:flutter/material.dart';
import 'package:connectivity_plus/connectivity_plus.dart';
import '../consts.dart';
/// NetworkController checks the network connection of the application globally
class NetworkController extends GetxController {
final Connectivity _connectivity = Connectivity();
@override
void onInit() {
super.onInit();
_connectivity.onConnectivityChanged.listen(_updateConnectionStatus);
}
void _updateConnectionStatus(ConnectivityResult connectivityResult) {
// If no network connection, show snack-bar
if (connectivityResult == ConnectivityResult.none) {
Get.rawSnackbar(
messageText: Text(
'You are not connected to the internet. The displayed information may be inaccurate.',
style: regTextStyle,
),
isDismissible: false,
duration: const Duration(days: 1), // Display the message until a network connection is established
backgroundColor: Colors.black45,
icon: const Icon(
Icons.wifi_off,
color: Colors.white,
size: 35,
),
margin: EdgeInsets.zero,
snackStyle: SnackStyle.GROUNDED,
);
} else {
if (Get.isSnackbarOpen) { // Close snack-bar upon establishing internet connection
Get.closeCurrentSnackbar();
}
}
}
}
\ No newline at end of file
......@@ -9,37 +9,47 @@ import '../server_requests/fetch_markers.dart';
import '../server_requests/fetch_relation.dart';
Future<void> initialiseState() async{
/// initialiseState makes three requests to the server, one requesting
/// measurements for the selected relation, the other requesting the relation,
/// and the last requesting the list of all system lakes
Future<void> initialiseState() async {
bool serverConnection = true;
late Future<List<Measurement>> markerListFuture;
late Future<Uint8List> relationFuture;
// Try to fetch measurement data from server
markerListFuture = fetchMeasurements().then((fetchResult) {
List<Measurement> measurements = fetchResult.measurements;
serverConnection = fetchResult.connected;
try {
// Try to fetch measurement data from server
markerListFuture = fetchMeasurements().then((fetchResult) {
List<Measurement> measurements = fetchResult.measurements;
serverConnection = fetchResult.connected;
// Return the measurements
return measurements;
}).catchError((error) {
serverConnection = false;
throw Exception("Failed to fetch measurements: $error");
});
// Return measurements
return measurements;
}).catchError((error) {
serverConnection = false;
throw Exception("Failed to fetch measurements: $error");
});
// Attempt to fetch relation from server if app establishes connection
if (serverConnection) {
relationFuture = fetchRelation();
} else { // Read last saved data
relationFuture = loadSavedRelation();
}
// If measurements were fetched successfully, request relation
if (serverConnection) {
relationFuture = fetchRelation();
} /*else { // Read last saved data
relationFuture = loadSavedRelation();
}*/
initSearchOptions();
initSearchOptions();
selectedRelation = await relationFuture;
selectedMarkerList = await markerListFuture;
//selectedRelation = await relationFuture;
selectedRelation = Uint8List(0);
selectedMarkerList = await markerListFuture;
} catch (e) {
// Handle any errors that occur during the initialization process
print("Error during initialization: $e");
}
}
/// initSearchOptions fetches a list of all lake names in the system
/// and initialises lakeSearchOptions
Future<void> initSearchOptions() async {
......
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
args:
dependency: transitive
description:
name: args
sha256: eef6c46b622e0494a36c5a12d10d77fb4e855501a91c1b9ef9339326e58f0596
url: "https://pub.dev"
source: hosted
version: "2.4.2"
async:
dependency: transitive
description:
......@@ -41,6 +49,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.18.0"
connectivity_plus:
dependency: "direct main"
description:
name: connectivity_plus
sha256: b74247fad72c171381dbe700ca17da24deac637ab6d43c343b42867acb95c991
url: "https://pub.dev"
source: hosted
version: "3.0.6"
connectivity_plus_platform_interface:
dependency: transitive
description:
name: connectivity_plus_platform_interface
sha256: cf1d1c28f4416f8c654d7dc3cd638ec586076255d407cef3ddbdaf178272a71a
url: "https://pub.dev"
source: hosted
version: "1.2.4"
crypto:
dependency: transitive
description:
......@@ -49,6 +73,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.0.3"
dbus:
dependency: transitive
description:
name: dbus
sha256: "365c771ac3b0e58845f39ec6deebc76e3276aa9922b0cc60840712094d9047ac"
url: "https://pub.dev"
source: hosted
version: "0.7.10"
equatable:
dependency: transitive
description:
......@@ -128,6 +160,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.5.1"
get:
dependency: "direct main"
description:
name: get
sha256: e4e7335ede17452b391ed3b2ede016545706c01a02292a6c97619705e7d2a85e
url: "https://pub.dev"
source: hosted
version: "4.6.6"
google_fonts:
dependency: "direct main"
description:
......@@ -160,6 +200,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.19.0"
js:
dependency: transitive
description:
name: js
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
url: "https://pub.dev"
source: hosted
version: "0.6.7"
latlong2:
dependency: "direct main"
description:
......@@ -248,6 +296,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.0.0"
nm:
dependency: transitive
description:
name: nm
sha256: "2c9aae4127bdc8993206464fcc063611e0e36e72018696cd9631023a31b24254"
url: "https://pub.dev"
source: hosted
version: "0.5.0"
path:
dependency: transitive
description:
......@@ -328,6 +384,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.11.1"
petitparser:
dependency: transitive
description:
name: petitparser
sha256: c15605cd28af66339f8eb6fbe0e541bfe2d1b72d5825efc6598f3e0a31b9ad27
url: "https://pub.dev"
source: hosted
version: "6.0.2"
platform:
dependency: transitive
description:
......@@ -573,6 +637,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.0.4"
xml:
dependency: transitive
description:
name: xml
sha256: b015a8ad1c488f66851d762d3090a21c600e479dc75e68328c52774040cf9226
url: "https://pub.dev"
source: hosted
version: "6.5.0"
sdks:
dart: ">=3.3.0 <4.0.0"
flutter: ">=3.19.0"
......@@ -9,9 +9,9 @@ environment:
dependencies:
flutter:
sdk: flutter
flutter_map: ^4.0.0 # Various maps
flutter_map: ^4.0.0 # Maps ans map customization
http: ^0.13.3 # HTTPS requests
latlong2: ^0.8.2
latlong2: ^0.8.2 # LatLng object
provider: ^5.0.0
fl_chart: ^0.20.0-nullsafety1 # Charts and diagrams
google_fonts: any # Fonts
......@@ -20,6 +20,8 @@ dependencies:
path_provider: ^2.0.8
shared_preferences: any # Persistent data storage
fuzzy: any # Search algorithm
connectivity_plus: ^3.0.3 # Check internet connection
get: ^4.6.5
dev_dependencies:
flutter_test:
......
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