From 6ed99248b3c72381236d550ff32fdd052d989988 Mon Sep 17 00:00:00 2001 From: alzalia1 Date: Thu, 14 Aug 2025 10:35:45 +0200 Subject: [PATCH] fix: switched to more user friendly datetimerange --- .../widget/pending/bal_pending_screen.dart | 47 +++++-------------- .../widgets/create_confirmation_popup.dart | 46 +++++------------- 2 files changed, 24 insertions(+), 69 deletions(-) diff --git a/lib/ui/bal_page/widget/pending/bal_pending_screen.dart b/lib/ui/bal_page/widget/pending/bal_pending_screen.dart index 99221e1..6f57c92 100644 --- a/lib/ui/bal_page/widget/pending/bal_pending_screen.dart +++ b/lib/ui/bal_page/widget/pending/bal_pending_screen.dart @@ -61,32 +61,21 @@ class _EditPopup extends State { final GlobalKey _formKey = GlobalKey(); String? name; DateTime? start; - Future _selectStart() async { - final DateTime? pickedDate = await showDatePicker( - context: context, - initialDate: start ?? widget.viewModel.bal!.startTime, - firstDate: DateTime.now(), - lastDate: DateTime(DateTime.now().year + 2), - locale: Locale("fr", "FR"), - ); - - setState(() { - start = pickedDate; - }); - } - DateTime? end; - Future _selectEnd() async { - final DateTime? pickedDate = await showDatePicker( + Future _selectRange() async { + final DateTimeRange? pickedDate = await showDateRangePicker( context: context, - initialDate: end ?? widget.viewModel.bal!.endTime, - firstDate: DateTime.now(), + firstDate: DateTime(DateTime.now().year - 1), lastDate: DateTime(DateTime.now().year + 2), - locale: Locale("fr", "FR"), + initialDateRange: DateTimeRange( + start: start ?? widget.viewModel.bal!.startTime, + end: end ?? widget.viewModel.bal!.endTime, + ), ); setState(() { - end = pickedDate; + start = pickedDate?.start; + end = pickedDate?.end; }); } @@ -125,24 +114,10 @@ class _EditPopup extends State { Text("Date de début : "), TextButton( onPressed: () { - _selectStart(); + _selectRange(); }, child: Text( - format.format(start ?? widget.viewModel.bal!.startTime), - locale: Locale("fr"), - ), - ), - ], - ), - Row( - children: [ - Text("Date de fin : "), - TextButton( - onPressed: () { - _selectEnd(); - }, - child: Text( - format.format(end ?? widget.viewModel.bal!.endTime), + "Du ${format.format(start ?? DateTime.now())}\nau ${format.format(end ?? DateTime.now().add(Duration(days: 1)))}", ), ), ], diff --git a/lib/ui/home_page/widgets/create_confirmation_popup.dart b/lib/ui/home_page/widgets/create_confirmation_popup.dart index a7ed3a9..bfa9fc2 100644 --- a/lib/ui/home_page/widgets/create_confirmation_popup.dart +++ b/lib/ui/home_page/widgets/create_confirmation_popup.dart @@ -17,32 +17,21 @@ class _CreateConfirmationPopupState extends State { final GlobalKey _formKey = GlobalKey(); String? name; DateTime? start; - Future _selectStart() async { - final DateTime? pickedDate = await showDatePicker( - context: context, - initialDate: start ?? DateTime.now(), - firstDate: DateTime.now(), - lastDate: DateTime(DateTime.now().year + 2), - locale: Locale("fr"), - ); - - setState(() { - start = pickedDate; - }); - } - DateTime? end; - Future _selectEnd() async { - final DateTime? pickedDate = await showDatePicker( + Future _selectRange() async { + final DateTimeRange? pickedDate = await showDateRangePicker( context: context, - initialDate: end ?? DateTime.now(), - firstDate: DateTime.now(), + firstDate: DateTime(DateTime.now().year - 1), lastDate: DateTime(DateTime.now().year + 2), - locale: Locale("fr"), + initialDateRange: DateTimeRange( + start: start ?? DateTime.now(), + end: end ?? DateTime.now().add(Duration(days: 1)), + ), ); setState(() { - end = pickedDate; + start = pickedDate?.start; + end = pickedDate?.end; }); } @@ -80,20 +69,11 @@ class _CreateConfirmationPopupState extends State { Text("Date de début : "), TextButton( onPressed: () { - _selectStart(); + _selectRange(); }, - child: Text(format.format(start ?? DateTime.now())), - ), - ], - ), - Row( - children: [ - Text("Date de fin : "), - TextButton( - onPressed: () { - _selectEnd(); - }, - child: Text(format.format(end ?? DateTime.now())), + child: Text( + "Du ${format.format(start ?? DateTime.now())}\nau ${format.format(end ?? DateTime.now().add(Duration(days: 1)))}", + ), ), ], ),