diff --git a/lib/presentation/screens/staff/policy/policy.dart b/lib/presentation/screens/staff/policy/policy.dart index 37e4be4..be821e1 100644 --- a/lib/presentation/screens/staff/policy/policy.dart +++ b/lib/presentation/screens/staff/policy/policy.dart @@ -1261,9 +1261,7 @@ class PolicyScreenState extends ConsumerState { return "Select start date first"; } - final startDate = DateFormat( - 'dd-MM-yyyy', - ).parse(startDateControllerText); + final startDate = DateFormat('dd-MM-yyyy').parse(startDateControllerText); final endDate = DateFormat('dd-MM-yyyy').parse(value); if (endDate.isBefore(startDate)) { @@ -1275,7 +1273,7 @@ class PolicyScreenState extends ConsumerState { startDate.year + 1, startDate.month, startDate.day, - ); + ).subtract(const Duration(days: 1)); if (endDate.isBefore(minEndDate)) { return "End date must be at least 1 year from start date"; diff --git a/lib/presentation/themes/indicators/date_field_theme.dart b/lib/presentation/themes/indicators/date_field_theme.dart index 643a803..eeb9ec6 100644 --- a/lib/presentation/themes/indicators/date_field_theme.dart +++ b/lib/presentation/themes/indicators/date_field_theme.dart @@ -40,9 +40,13 @@ class _ThemedDateFieldState extends State { BuildContext context, FormFieldState field, ) async { + DateTime initialDate = selectedDate ?? + (widget.controller?.text.isNotEmpty == true + ? DateFormat('dd-MM-yyyy').parse(widget.controller!.text) + : DateTime.now()); final pickedDate = await showDatePicker( context: context, - initialDate: selectedDate ?? DateTime.now(), + initialDate: initialDate, firstDate: DateTime(2000), // lastDate: DateTime(2100), lastDate: widget.lastDate ?? DateTime(2100),