Merged code

This commit is contained in:
venba-Inspriron-3558 2025-06-27 13:01:35 +05:30
commit e15666e3b8
2 changed files with 65 additions and 10 deletions

View File

@ -167,9 +167,31 @@ class _AccomodationScreenState extends State<AccomodationScreen> {
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<AccomodationScreen> {
}
}
DateTime? _parseDateSafe(String? dateStr, DateFormat formatter) {
try {
if (dateStr == null || dateStr.isEmpty) return null;
return formatter.parseStrict(dateStr);
} catch (e) {
return null;
}
}
Map<String, String?> getFlightTripDateRange(
List<Map<String, dynamic>> flightData,
) {
print("FlightDAta - ${widget.flightData}");
final allTrips =
flightData
.expand((flight) => flight['trips'] ?? [])
@ -250,7 +283,7 @@ class _AccomodationScreenState extends State<AccomodationScreen> {
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<AccomodationScreen> {
});
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<String, dynamic> 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: () => <String, dynamic>{});
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'],
};
}

View File

@ -338,8 +338,10 @@ class _ForexScreenState extends State<ForexScreen> {
.whereType<Map<String, dynamic>>()
.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<ForexScreen> {
return {
'firstTripDate': firstTrip['date'],
'lastTripDate': lastTrip['date'],
'toTripPlace' : toPlaceCode
'toTripPlace': toPlaceCode,
};
}
@ -501,7 +503,8 @@ class _ForexScreenState extends State<ForexScreen> {
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<ForexScreen> {
// 'dd-MM-yyyy',
// ).format(parsedEndDate);
// }
_onFieldChanged();
_onFieldChanged();
handleUpdatedField();
});
}