selectTrip method

void selectTrip(
  1. OfferModel trip,
  2. void onSelected()
)

Implementation

void selectTrip(OfferModel trip, void Function() onSelected) async {
  if (trip.offerId == null) {
    CustomFlashWidget.showFlashMessage(
      type: FlashType.error,
      title: "Invalid trip",
      message: "The trip you selected is not found",
    );
    return;
  }

  if (searchExpireTimerCount.value < 1) {
    if (currentRoute() == Routes.FLIGHT_SEARCH) {
      SessionExpiredDialog.show(
        barrierDismissible: false,
        title: 'Booking Session Expired',
        content:
            'Your 30-minute booking session has expired, and the selected flight is no longer reserved. To continue, you can either search for a new flight or review your NEOPASS Search History to quickly find similar options.',
      );
    }
    return;
  }

  expandedIndex.value = -1;
  estimateQuote.value = null;
  selectedStandardOffer.value = null;
  selectedExclusiveOffer.value = trip;
  if(isRoundTrip && !(trip.updatedOnlinePrice?? true)){
    final estimate =  await getEstimatedOnlinePrice();
     if(estimate?.estimate != null){
      final index = filteredList.indexWhere((e)=>(e is OfferModel) ? e.offerId == trip.offerId: false);
     filteredList[index] = (filteredList[index] as OfferModel).copyWith(
        estimate: estimate,
        updatedOnlinePrice: true
      );
     }
  } else{
    estimateQuote.value = trip.estimate;
  }
  currentTab.value = 1;
  onSelected();
  await Future.delayed(const Duration(milliseconds: 250));
  initPassengers();
  if (selectedExclusiveOffer.value != null) {
    Requests.box
        .write('departureTrip', selectedExclusiveOffer.value?.toJson());
  } else {
    Requests.box.remove('departureTrip');
  }
  Requests.box.save();

}