refactoring and checkpoint
This commit is contained in:
@@ -1,38 +1,82 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||
|
||||
class LocationPickerScreen extends StatelessWidget {
|
||||
const LocationPickerScreen({super.key});
|
||||
/// É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 une localisation'),
|
||||
backgroundColor: const Color(0xFF1E1E2C),
|
||||
title: const Text('Sélectionnez un lieu'),
|
||||
backgroundColor: Colors.blueAccent,
|
||||
),
|
||||
body: GoogleMap(
|
||||
initialCameraPosition: const CameraPosition(
|
||||
target: LatLng(48.8566, 2.3522), // Paris par défaut
|
||||
zoom: 12.0,
|
||||
),
|
||||
markers: <Marker>{
|
||||
Marker(
|
||||
markerId: const MarkerId('selectedLocation'),
|
||||
position: const LatLng(48.8566, 2.3522), // Position par défaut
|
||||
draggable: true,
|
||||
onDragEnd: (newPosition) {
|
||||
print('Nouvelle position sélectionnée: $newPosition');
|
||||
Navigator.of(context).pop(newPosition);
|
||||
},
|
||||
)
|
||||
},
|
||||
onTap: (position) {
|
||||
print('Position tapée: $position');
|
||||
Navigator.of(context).pop(position);
|
||||
},
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user