73 lines
3.0 KiB
Dart
73 lines
3.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
|
|
|
import '../../screens/location/location_picker_Screen.dart';
|
|
|
|
/// `LocationField` est un champ de saisie permettant de sélectionner une localisation sur une carte.
|
|
/// Il utilise la page `LocationPickerScreen` pour permettre à l'utilisateur de choisir un emplacement précis.
|
|
/// Ce widget est utilisé dans des formulaires et permet d'afficher la localisation sélectionnée.
|
|
///
|
|
/// Arguments :
|
|
/// - `location`: Une chaîne représentant la localisation actuelle à afficher.
|
|
/// - `selectedLatLng`: Une variable de type `LatLng?` représentant la latitude et la longitude de la localisation sélectionnée.
|
|
/// - `onLocationPicked`: Un callback pour retourner la localisation choisie par l'utilisateur.
|
|
///
|
|
class LocationField extends StatelessWidget {
|
|
final String location;
|
|
final LatLng? selectedLatLng;
|
|
final Function(LatLng?) onLocationPicked;
|
|
|
|
const LocationField({Key? key, required this.location, this.selectedLatLng, required this.onLocationPicked})
|
|
: super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
// Log : Construction du champ LocationField
|
|
debugPrint('Construction du champ LocationField');
|
|
|
|
return GestureDetector(
|
|
onTap: () async {
|
|
// Log : L'utilisateur clique pour choisir une localisation
|
|
debugPrint('Utilisateur clique pour choisir une localisation');
|
|
|
|
final LatLng? pickedLocation = await Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) => const LocationPickerScreen(),
|
|
),
|
|
);
|
|
|
|
if (pickedLocation != null) {
|
|
// Log : L'utilisateur a sélectionné une nouvelle localisation
|
|
debugPrint('Nouvelle localisation sélectionnée : $pickedLocation');
|
|
onLocationPicked(pickedLocation);
|
|
}
|
|
},
|
|
child: AnimatedContainer(
|
|
duration: const Duration(milliseconds: 300), // Animation fluide lors du focus
|
|
padding: const EdgeInsets.symmetric(vertical: 12.0, horizontal: 16.0),
|
|
decoration: BoxDecoration(
|
|
color: Colors.blueGrey.withOpacity(0.1), // Fond plus visible, subtilement coloré
|
|
borderRadius: BorderRadius.circular(12.0), // Bordure arrondie améliorée
|
|
border: Border.all(
|
|
color: selectedLatLng == null ? Colors.blueGrey.withOpacity(0.5) : Colors.blue, // Bordure change selon l'état
|
|
width: 2.0,
|
|
),
|
|
),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(
|
|
selectedLatLng == null
|
|
? 'Sélectionnez une localisation' // Message par défaut si aucune localisation sélectionnée
|
|
: 'Localisation: $location', // Affiche la localisation actuelle
|
|
style: const TextStyle(color: Colors.blueGrey, fontSize: 16.0),
|
|
),
|
|
const Icon(Icons.location_on, color: Colors.blueGrey),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|