66 lines
2.1 KiB
Dart
66 lines
2.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
class DatePickerField extends StatelessWidget {
|
|
final DateTime? selectedDate;
|
|
final Function(DateTime?) onDatePicked;
|
|
final String label; // Texte du label
|
|
|
|
const DatePickerField({
|
|
Key? key,
|
|
this.selectedDate,
|
|
required this.onDatePicked,
|
|
this.label = 'Sélectionnez une date', // Label par défaut
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return GestureDetector(
|
|
onTap: () async {
|
|
final DateTime? picked = await showDatePicker(
|
|
context: context,
|
|
initialDate: DateTime.now(),
|
|
firstDate: DateTime.now(),
|
|
lastDate: DateTime(2101),
|
|
);
|
|
if (picked != null) {
|
|
onDatePicked(picked);
|
|
}
|
|
},
|
|
child: Container(
|
|
padding: const EdgeInsets.symmetric(vertical: 14.0, horizontal: 18.0),
|
|
decoration: BoxDecoration(
|
|
color: Colors.blueGrey.withOpacity(0.1), // Fond plus doux et moderne
|
|
borderRadius: BorderRadius.circular(12.0), // Coins arrondis plus prononcés
|
|
border: Border.all(color: Colors.blueGrey.withOpacity(0.5), width: 2.0), // Bordure légère
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.black12,
|
|
offset: Offset(0, 4),
|
|
blurRadius: 8,
|
|
),
|
|
],
|
|
),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(
|
|
selectedDate == null
|
|
? label
|
|
: '${selectedDate!.day}/${selectedDate!.month}/${selectedDate!.year}',
|
|
style: const TextStyle(
|
|
color: Colors.blueGrey, // Couleur du texte adaptée
|
|
fontSize: 16.0, // Taille de police améliorée
|
|
fontWeight: FontWeight.w600, // Poids de police plus important pour un meilleur contraste
|
|
),
|
|
),
|
|
Icon(
|
|
Icons.calendar_today,
|
|
color: Colors.blueGrey, // Couleur de l'icône assortie au texte
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|