set kilometer in double

This commit is contained in:
Valentin CZERYBA 2025-01-09 23:27:22 +01:00
parent 18d5c83181
commit 54c95a230b
3 changed files with 17 additions and 4 deletions

View File

@ -3,6 +3,7 @@ import 'package:shared_preferences/shared_preferences.dart';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'dart:io'; import 'dart:io';
import '../pages/EditProfile.dart'; import '../pages/EditProfile.dart';
import '../pages/EditSettings.dart';
import '../pages/ListItemMenu.dart'; import '../pages/ListItemMenu.dart';
import 'alert.dart'; import 'alert.dart';
@ -105,7 +106,10 @@ class MyDrawer extends StatelessWidget with ShowAlertDialog {
leading: Icon(Icons.settings), leading: Icon(Icons.settings),
title: Text('Settings'), title: Text('Settings'),
onTap: () { onTap: () {
Navigator.pop(context); // Close the drawer Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (_) => EditSettings())); // Close the drawer
}, },
), ),
ListTile( ListTile(

View File

@ -38,9 +38,16 @@ class _EditProfileState extends State<EditSettings>
Future<void> getParameter() async { Future<void> getParameter() async {
SharedPreferences prefs = await SharedPreferences.getInstance(); SharedPreferences prefs = await SharedPreferences.getInstance();
setState(() {
var kilometer = prefs.getDouble("kilometer")?.toInt() ?? null;
});
}
Future<void> setParameter() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
if (kilometer != null) { if (kilometer != null) {
var kilometer = prefs.getInt("kilometer") ?? null; prefs.setDouble("kilometer", kilometer?.toDouble() ?? 50);
showAlertDialog(context, "Update", "Mise à jour des paramètres");
} }
} }

View File

@ -93,9 +93,11 @@ class _MyHomePageState extends State<ListItemMenu> {
print('No last known position available.'); print('No last known position available.');
} }
} }
SharedPreferences prefs = await SharedPreferences.getInstance();
if (position != null) { if (position != null) {
// Calculate the boundaries // Calculate the boundaries
double radiusInKm = 50; double radiusInKm = prefs.getDouble("kilometer") ?? 50;
double latDistance = radiusInKm / 111.0; double latDistance = radiusInKm / 111.0;
double lonDistance = double lonDistance =
radiusInKm / (111.0 * cos(position.latitude * pi / 180)); radiusInKm / (111.0 * cos(position.latitude * pi / 180));
@ -109,7 +111,7 @@ class _MyHomePageState extends State<ListItemMenu> {
"?min_lat=$minLat&max_lat=$maxLat" "?min_lat=$minLat&max_lat=$maxLat"
"&min_lon=$minLon&max_lon=$maxLon&current_datetime=${currentDatetime.toString()}"); "&min_lon=$minLon&max_lon=$maxLon&current_datetime=${currentDatetime.toString()}");
} }
SharedPreferences prefs = await SharedPreferences.getInstance();
var accessToken = prefs.getString("access_token") ?? ""; var accessToken = prefs.getString("access_token") ?? "";
if (accessToken.isNotEmpty) { if (accessToken.isNotEmpty) {