accomdoation changes
This commit is contained in:
parent
57f7f29054
commit
ae31d1fea5
@ -167,9 +167,31 @@ class _AccomodationScreenState extends State<AccomodationScreen> {
|
|||||||
|
|
||||||
print("Rs: $result");
|
print("Rs: $result");
|
||||||
|
|
||||||
flightFirstTripDateNotifier.value = result['firstTripDate'];
|
print("updat- ${widget.selectedItem}");
|
||||||
flightLastTripDateNotifier.value = result['lastTripDate'];
|
final checkinDate =
|
||||||
flightFirstToDestinationNotifier.value = result['firstToDestination'];
|
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(
|
print(
|
||||||
"flightfirstToDestinationNotifier: $flightFirstToDestinationNotifier.value ",
|
"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(
|
Map<String, String?> getFlightTripDateRange(
|
||||||
List<Map<String, dynamic>> flightData,
|
List<Map<String, dynamic>> flightData,
|
||||||
) {
|
) {
|
||||||
|
print("FlightDAta - ${widget.flightData}");
|
||||||
|
|
||||||
final allTrips =
|
final allTrips =
|
||||||
flightData
|
flightData
|
||||||
.expand((flight) => flight['trips'] ?? [])
|
.expand((flight) => flight['trips'] ?? [])
|
||||||
@ -250,7 +283,7 @@ class _AccomodationScreenState extends State<AccomodationScreen> {
|
|||||||
if (allTrips.isEmpty) {
|
if (allTrips.isEmpty) {
|
||||||
return {'firstTripDate': null, 'lastTripDate': null};
|
return {'firstTripDate': null, 'lastTripDate': null};
|
||||||
}
|
}
|
||||||
|
final DateFormat dateFormatter = DateFormat('dd-MM-yyyy');
|
||||||
allTrips.sort((a, b) {
|
allTrips.sort((a, b) {
|
||||||
final aDate = DateTime.tryParse(a['date'] ?? '') ?? DateTime(1900);
|
final aDate = DateTime.tryParse(a['date'] ?? '') ?? DateTime(1900);
|
||||||
final bDate = DateTime.tryParse(b['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 firstTrip = allTrips.first;
|
||||||
final lastTrip = allTrips.last;
|
// final lastTrip = allTrips.last;
|
||||||
final firstTripToDestination = allTrips.first;
|
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");
|
print("allTrips - $allTrips");
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'firstTripDate': firstTrip['date'],
|
'firstTripDate': firstTrip['date'],
|
||||||
'lastTripDate': lastTrip['date'],
|
'lastTripDate': nextTrip != null ? nextTrip['date'] : null,
|
||||||
|
|
||||||
|
// 'lastTripDate': nextTrip['date'],
|
||||||
|
// 'lastTripDate': lastTrip['date'],
|
||||||
'firstToDestination': firstTripToDestination['to_place'],
|
'firstToDestination': firstTripToDestination['to_place'],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -338,8 +338,10 @@ class _ForexScreenState extends State<ForexScreen> {
|
|||||||
.whereType<Map<String, dynamic>>()
|
.whereType<Map<String, dynamic>>()
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
|
print("ALlTrips- $allTrips");
|
||||||
|
|
||||||
if (allTrips.isEmpty) {
|
if (allTrips.isEmpty) {
|
||||||
return {'firstTripDate': null, 'lastTripDate': null, 'toTripPlace' : null};
|
return {'firstTripDate': null, 'lastTripDate': null, 'toTripPlace': null};
|
||||||
}
|
}
|
||||||
|
|
||||||
allTrips.sort((a, b) {
|
allTrips.sort((a, b) {
|
||||||
@ -355,7 +357,7 @@ class _ForexScreenState extends State<ForexScreen> {
|
|||||||
return {
|
return {
|
||||||
'firstTripDate': firstTrip['date'],
|
'firstTripDate': firstTrip['date'],
|
||||||
'lastTripDate': lastTrip['date'],
|
'lastTripDate': lastTrip['date'],
|
||||||
'toTripPlace' : toPlaceCode
|
'toTripPlace': toPlaceCode,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -501,7 +503,8 @@ class _ForexScreenState extends State<ForexScreen> {
|
|||||||
if (toPlaceCountryCode != null && toPlaceCountryCode.trim().isNotEmpty) {
|
if (toPlaceCountryCode != null && toPlaceCountryCode.trim().isNotEmpty) {
|
||||||
try {
|
try {
|
||||||
if (toPlaceCountryCode != null) {
|
if (toPlaceCountryCode != null) {
|
||||||
textControllers["_countries"]?.text = toPlaceCountryCode; // set country dropdown
|
textControllers["_countries"]?.text =
|
||||||
|
toPlaceCountryCode; // set country dropdown
|
||||||
selectedCountry = toPlaceCountryCode;
|
selectedCountry = toPlaceCountryCode;
|
||||||
// textControllers["_countriesFocused"]?.addListener( _onFieldChanged ); // Reattach
|
// textControllers["_countriesFocused"]?.addListener( _onFieldChanged ); // Reattach
|
||||||
// _onFieldChanged;
|
// _onFieldChanged;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user