From 1b97c16c2acd1162eaf5ecf43837388a331caef1 Mon Sep 17 00:00:00 2001 From: venba-Inspriron-3558 Date: Sat, 11 Oct 2025 16:52:01 +0530 Subject: [PATCH] FIX_policy date one year validation --- lib/presentation/screens/staff/policy/policy.dart | 6 ++---- lib/presentation/themes/indicators/date_field_theme.dart | 6 +++++- 2 files changed, 7 insertions(+), 5 deletions(-) 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),