diff --git a/covas_mobile/lib/classes/MyDrawer.dart b/covas_mobile/lib/classes/MyDrawer.dart index f76fb68..df4bc42 100644 --- a/covas_mobile/lib/classes/MyDrawer.dart +++ b/covas_mobile/lib/classes/MyDrawer.dart @@ -3,6 +3,7 @@ import 'package:shared_preferences/shared_preferences.dart'; import 'package:http/http.dart' as http; import 'dart:io'; import '../pages/EditProfile.dart'; +import '../pages/EditSettings.dart'; import '../pages/ListItemMenu.dart'; import 'alert.dart'; @@ -105,7 +106,10 @@ class MyDrawer extends StatelessWidget with ShowAlertDialog { leading: Icon(Icons.settings), title: Text('Settings'), onTap: () { - Navigator.pop(context); // Close the drawer + Navigator.pushReplacement( + context, + MaterialPageRoute( + builder: (_) => EditSettings())); // Close the drawer }, ), ListTile( diff --git a/covas_mobile/lib/pages/EditSettings.dart b/covas_mobile/lib/pages/EditSettings.dart index 0f91293..8ce10e3 100644 --- a/covas_mobile/lib/pages/EditSettings.dart +++ b/covas_mobile/lib/pages/EditSettings.dart @@ -38,9 +38,16 @@ class _EditProfileState extends State Future getParameter() async { SharedPreferences prefs = await SharedPreferences.getInstance(); + setState(() { + var kilometer = prefs.getDouble("kilometer")?.toInt() ?? null; + }); + } + Future setParameter() async { + SharedPreferences prefs = await SharedPreferences.getInstance(); if (kilometer != null) { - var kilometer = prefs.getInt("kilometer") ?? null; + prefs.setDouble("kilometer", kilometer?.toDouble() ?? 50); + showAlertDialog(context, "Update", "Mise à jour des paramètres"); } } diff --git a/covas_mobile/lib/pages/ListItemMenu.dart b/covas_mobile/lib/pages/ListItemMenu.dart index eb99976..46dc868 100644 --- a/covas_mobile/lib/pages/ListItemMenu.dart +++ b/covas_mobile/lib/pages/ListItemMenu.dart @@ -93,9 +93,11 @@ class _MyHomePageState extends State { print('No last known position available.'); } } + SharedPreferences prefs = await SharedPreferences.getInstance(); + if (position != null) { // Calculate the boundaries - double radiusInKm = 50; + double radiusInKm = prefs.getDouble("kilometer") ?? 50; double latDistance = radiusInKm / 111.0; double lonDistance = radiusInKm / (111.0 * cos(position.latitude * pi / 180)); @@ -109,7 +111,7 @@ class _MyHomePageState extends State { "?min_lat=$minLat&max_lat=$maxLat" "&min_lon=$minLon&max_lon=$maxLon¤t_datetime=${currentDatetime.toString()}"); } - SharedPreferences prefs = await SharedPreferences.getInstance(); + var accessToken = prefs.getString("access_token") ?? ""; if (accessToken.isNotEmpty) {