83 lines
2.8 KiB
Dart
83 lines
2.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
|
|
|
/// Écran pour la sélection d'une localisation sur une carte.
|
|
/// L'utilisateur peut choisir un lieu en interagissant avec la carte Google Maps.
|
|
/// Des logs permettent de tracer les actions comme la sélection et l'affichage de la carte.
|
|
class LocationPickerScreen extends StatefulWidget {
|
|
const LocationPickerScreen({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
_LocationPickerScreenState createState() => _LocationPickerScreenState();
|
|
}
|
|
|
|
class _LocationPickerScreenState extends State<LocationPickerScreen> {
|
|
LatLng _pickedLocation = const LatLng(37.7749, -122.4194); // Localisation par défaut (San Francisco)
|
|
late GoogleMapController _mapController; // Contrôleur de la carte Google Maps
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
print('Affichage de l\'écran de sélection de localisation.');
|
|
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('Sélectionnez un lieu'),
|
|
backgroundColor: Colors.blueAccent,
|
|
),
|
|
body: Column(
|
|
children: [
|
|
Expanded(
|
|
child: GoogleMap(
|
|
initialCameraPosition: CameraPosition(
|
|
target: _pickedLocation,
|
|
zoom: 14,
|
|
),
|
|
onMapCreated: (controller) {
|
|
_mapController = controller;
|
|
print('Carte Google Maps créée.');
|
|
},
|
|
onTap: _selectLocation, // Sélection de la localisation sur la carte
|
|
markers: {
|
|
Marker(
|
|
markerId: const MarkerId('pickedLocation'),
|
|
position: _pickedLocation,
|
|
),
|
|
},
|
|
),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.all(16.0),
|
|
child: ElevatedButton.icon(
|
|
onPressed: () {
|
|
print('Lieu sélectionné : $_pickedLocation');
|
|
Navigator.of(context).pop(_pickedLocation);
|
|
},
|
|
icon: const Icon(Icons.check),
|
|
label: const Text('Confirmer la localisation'),
|
|
style: ElevatedButton.styleFrom(
|
|
minimumSize: const Size(double.infinity, 50),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
/// Fonction pour gérer la sélection d'une localisation sur la carte.
|
|
/// Lorsqu'une localisation est sélectionnée, elle est ajoutée à la carte et les logs sont mis à jour.
|
|
void _selectLocation(LatLng position) {
|
|
setState(() {
|
|
_pickedLocation = position;
|
|
});
|
|
print('Localisation sélectionnée : $_pickedLocation');
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_mapController.dispose();
|
|
print('Libération des ressources de la carte.');
|
|
super.dispose();
|
|
}
|
|
}
|