merge commit

This commit is contained in:
Valentin CZERYBA 2024-11-23 09:56:37 +01:00
parent 93beabe884
commit f693ffa6b8

View File

@ -137,8 +137,6 @@ class _MyHomePageState extends State<ListItemMenu> {
super.initState(); super.initState();
// Initialize data fetch when the page loads // Initialize data fetch when the page loads
_getCurrentLocation(); _getCurrentLocation();
Datepicker.text = DateFormat("dd-MM-yyyy").format(new DateTime.now());
} }
// Get the device's current location // Get the device's current location
@ -149,19 +147,32 @@ class _MyHomePageState extends State<ListItemMenu> {
print("Location permission granted"); print("Location permission granted");
// Get the current position with high accuracy // Get the current position with high accuracy
LocationSettings locationSettings = LocationSettings( const LocationSettings locationSettings = LocationSettings(
accuracy: LocationAccuracy.high, accuracy: LocationAccuracy.medium, timeLimit: Duration(seconds: 5));
distanceFilter: Position? position;
10, // Optional: Minimum distance (in meters) to trigger location update try {
); position = await Geolocator.getCurrentPosition(
locationSettings: locationSettings);
Position position = await Geolocator.getCurrentPosition( } on LocationServiceDisabledException {
locationSettings: locationSettings, // Handle location services disabled
); print('Location services are disabled.');
position = await Geolocator.getLastKnownPosition();
if (position == null) {
print('No last known position available.');
}
} catch (e) {
// Handle other errors
print('Failed to get location: $e');
position = await Geolocator.getLastKnownPosition();
if (position == null) {
print('No last known position available.');
}
}
// Reverse geocode: Get city and country from latitude and longitude using Mapbox Search API // Reverse geocode: Get city and country from latitude and longitude using Mapbox Search API
final place = if (position != null) {
await _getCityAndCountry(position.latitude, position.longitude); _getCityAndCountry(position!.latitude, position!.longitude);
}
} }
} }
@ -321,10 +332,7 @@ class _MyHomePageState extends State<ListItemMenu> {
DateTime dateEvent = DateTime.now(); DateTime dateEvent = DateTime.now();
DateTime? pickedDate = await showDatePicker( DateTime? pickedDate = await showDatePicker(
context: context, context: context, firstDate: dateEvent, lastDate: DateTime(2104));
firstDate: dateEvent,
initialDate: dateEvent,
lastDate: DateTime(2104));
if (pickedDate == null) return; if (pickedDate == null) return;
Datepicker.text = DateFormat("dd-MM-yyyy").format(pickedDate); Datepicker.text = DateFormat("dd-MM-yyyy").format(pickedDate);
} }