From ae31d1fea56aa2532a834a3f38f6fc74e848dda1 Mon Sep 17 00:00:00 2001 From: venbaittech Date: Fri, 27 Jun 2025 10:54:16 +0530 Subject: [PATCH] accomdoation changes --- lib/Screens/itnerary/accomodations.dart | 64 ++++++++++++++++++++++--- lib/Screens/itnerary/forex.dart | 11 +++-- 2 files changed, 65 insertions(+), 10 deletions(-) diff --git a/lib/Screens/itnerary/accomodations.dart b/lib/Screens/itnerary/accomodations.dart index 266b643..b628dcf 100644 --- a/lib/Screens/itnerary/accomodations.dart +++ b/lib/Screens/itnerary/accomodations.dart @@ -167,9 +167,31 @@ class _AccomodationScreenState extends State { print("Rs: $result"); - flightFirstTripDateNotifier.value = result['firstTripDate']; - flightLastTripDateNotifier.value = result['lastTripDate']; - flightFirstToDestinationNotifier.value = result['firstToDestination']; + print("updat- ${widget.selectedItem}"); + final checkinDate = + widget.selectedItem?["checkin_date"] ?? result['firstTripDate']; + final checkoutDate = + widget.selectedItem?["checkout_date"] ?? result['lastTripDate']; + final destinationCity = + widget.selectedItem?["destination_city"] ?? + result['firstToDestination']; + + if (checkinDate != null) { + flightFirstTripDateNotifier.value = checkinDate; + } + + if (checkoutDate != null) { + flightLastTripDateNotifier.value = checkoutDate; + } + + if (destinationCity != null) { + flightFirstToDestinationNotifier.value = destinationCity; + } + + // flightFirstTripDateNotifier.value = result['firstTripDate']; + // flightLastTripDateNotifier.value = result['lastTripDate']; + // flightFirstToDestinationNotifier.value = result['firstToDestination']; + // print( "flightfirstToDestinationNotifier: $flightFirstToDestinationNotifier.value ", @@ -238,9 +260,20 @@ class _AccomodationScreenState extends State { } } + DateTime? _parseDateSafe(String? dateStr, DateFormat formatter) { + try { + if (dateStr == null || dateStr.isEmpty) return null; + return formatter.parseStrict(dateStr); + } catch (e) { + return null; + } + } + Map getFlightTripDateRange( List> flightData, ) { + print("FlightDAta - ${widget.flightData}"); + final allTrips = flightData .expand((flight) => flight['trips'] ?? []) @@ -250,7 +283,7 @@ class _AccomodationScreenState extends State { if (allTrips.isEmpty) { return {'firstTripDate': null, 'lastTripDate': null}; } - + final DateFormat dateFormatter = DateFormat('dd-MM-yyyy'); allTrips.sort((a, b) { final aDate = DateTime.tryParse(a['date'] ?? '') ?? DateTime(1900); final bDate = DateTime.tryParse(b['date'] ?? '') ?? DateTime(1900); @@ -258,14 +291,33 @@ class _AccomodationScreenState extends State { }); final firstTrip = allTrips.first; - final lastTrip = allTrips.last; + // final lastTrip = allTrips.last; final firstTripToDestination = allTrips.first; + final firstTripDate = _parseDateSafe(firstTrip['date'], dateFormatter); + + print("res1 - ${firstTrip['date']},"); + print("res11 - $firstTripDate"); + + // Use `List.where` instead of `firstWhere` so you can handle an empty result + + final Map nextTrip = allTrips.skip(1).firstWhere((trip) { + final DateFormat dateFormatter = DateFormat('dd-MM-yyyy'); + final tripDate = dateFormatter.tryParse(trip['date'] ?? ''); + return tripDate != null && + firstTripDate != null && + tripDate.isAfter(firstTripDate); + }, orElse: () => {}); + print("res2 - $nextTrip"); + print("allTrips - $allTrips"); return { 'firstTripDate': firstTrip['date'], - 'lastTripDate': lastTrip['date'], + 'lastTripDate': nextTrip != null ? nextTrip['date'] : null, + + // 'lastTripDate': nextTrip['date'], + // 'lastTripDate': lastTrip['date'], 'firstToDestination': firstTripToDestination['to_place'], }; } diff --git a/lib/Screens/itnerary/forex.dart b/lib/Screens/itnerary/forex.dart index 090babc..a27f3f6 100644 --- a/lib/Screens/itnerary/forex.dart +++ b/lib/Screens/itnerary/forex.dart @@ -338,8 +338,10 @@ class _ForexScreenState extends State { .whereType>() .toList(); + print("ALlTrips- $allTrips"); + if (allTrips.isEmpty) { - return {'firstTripDate': null, 'lastTripDate': null, 'toTripPlace' : null}; + return {'firstTripDate': null, 'lastTripDate': null, 'toTripPlace': null}; } allTrips.sort((a, b) { @@ -355,7 +357,7 @@ class _ForexScreenState extends State { return { 'firstTripDate': firstTrip['date'], 'lastTripDate': lastTrip['date'], - 'toTripPlace' : toPlaceCode + 'toTripPlace': toPlaceCode, }; } @@ -501,7 +503,8 @@ class _ForexScreenState extends State { if (toPlaceCountryCode != null && toPlaceCountryCode.trim().isNotEmpty) { try { if (toPlaceCountryCode != null) { - textControllers["_countries"]?.text = toPlaceCountryCode; // set country dropdown + textControllers["_countries"]?.text = + toPlaceCountryCode; // set country dropdown selectedCountry = toPlaceCountryCode; // textControllers["_countriesFocused"]?.addListener( _onFieldChanged ); // Reattach // _onFieldChanged; @@ -523,7 +526,7 @@ class _ForexScreenState extends State { // 'dd-MM-yyyy', // ).format(parsedEndDate); // } - _onFieldChanged(); + _onFieldChanged(); handleUpdatedField(); }); }