build method

  1. @override
Widget build(
  1. BuildContext context
)
override

Describes the part of the user interface represented by this widget.

The framework calls this method when this widget is inserted into the tree in a given BuildContext and when the dependencies of this widget change (e.g., an InheritedWidget referenced by this widget changes). This method can potentially be called in every frame and should not have any side effects beyond building a widget.

The framework replaces the subtree below this widget with the widget returned by this method, either by updating the existing subtree or by removing the subtree and inflating a new subtree, depending on whether the widget returned by this method can update the root of the existing subtree, as determined by calling Widget.canUpdate.

Typically implementations return a newly created constellation of widgets that are configured with information from this widget's constructor and from the given BuildContext.

The given BuildContext contains information about the location in the tree at which this widget is being built. For example, the context provides the set of inherited widgets for this location in the tree. A given widget might be built with multiple different BuildContext arguments over time if the widget is moved around the tree or if the widget is inserted into the tree in multiple places at once.

The implementation of this method must only depend on:

If a widget's build method is to depend on anything else, use a StatefulWidget instead.

See also:

  • StatelessWidget, which contains the discussion on performance considerations.

Implementation

@override
Widget build(BuildContext context) {
  return LayoutBuilder(builder: (context, constraints) {
    return Obx(() {
      final isCompleted  =  controller.selectedBooking.value.payment?.status == 'COMPLETED';
      final isUsingMiles =
          history.bookingStatus == BookingStatus.pendingPayment
              ? controller.isMilesUsed.value
              : (history.usedNeoMiles ?? false);
      final int milesPercentage =
          history.bookingStatus == BookingStatus.pendingPayment
              ? controller.milesPercentage
              : int.parse(history.neoMilesPercentage ?? '0');
      final savedSmart = (double.parse(history.totalOnlinePrice.toString())) - (double.parse(history.totalDiscountedPrice.toString()));

      String formatPrice(String? price) {
        if (price == null || price.isEmpty) return "0";
        final num? parsedPrice = num.tryParse(price);
        if (parsedPrice == null) return "0";

        final formatter = NumberFormat("#,###");
        return formatter.format(parsedPrice);
      }



      return Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            'Payment Summary',
            style: TextStyle(
              fontSize: 14.dp,
              fontWeight: FontWeight.w600,
              color: ColorHelper.textDark,
            ),
          ),
          1.5.h.SpaceX,
          _paymentSummaryRowWidget(
            children: [
              Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Row(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Container(
                        width: 44.dp,
                        height: 44.dp,
                        alignment: Alignment.center,
                        decoration: BoxDecoration(
                          color: Colors.white,
                          borderRadius: BorderRadius.circular(12),
                          boxShadow: [
                            BoxShadow(
                              color: ColorHelper.shadowColor.withOpacity(0.15),
                              spreadRadius: 0.0,
                              blurRadius: 16.0,
                              offset: const Offset(0, 4),
                            ),
                          ],
                        ),
                        child: SvgPicture.asset('assets/myflights/payment2.svg'),
                      ),
                      12.SpaceY,
                      Expanded(
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Text(
                              'Total price of the booking',
                              style: TextStyle(
                                fontSize: 12.dp,
                                fontWeight: FontWeight.w500,
                                color: ColorHelper.neutralDark,
                              ),
                            ),
                            Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Text(
                                  'Payment Method : ${history.payment?.type??'Not Avaible'}',
                                  style: TextStyle(
                                    fontSize: 10.dp,
                                    fontWeight: FontWeight.w400,
                                    color: ColorHelper.neutralLightText,
                                  ),
                                ),
                                Text(
                                 '${controller.currency} ${history.grandTotal ?? '0'}',
                                  style: TextStyle(
                                    fontSize: 14.dp,
                                    fontWeight: FontWeight.w600,
                                    color: ColorHelper.neutralMediumText,
                                  ),
                                ),
                              ],
                            ),
                            Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Text(
                                  history.payment?.type?.toLowerCase() !='card' ?'Crypto currency Transaction Hash :': 'Tranasaction Hash',
                                  style: TextStyle(
                                    fontSize: 10.dp,
                                    fontWeight: FontWeight.w400,
                                    color: ColorHelper.neutralLightText,
                                  ),
                                ),
                                Text(
                                  history.paymentReference ?? 'Not Available',
                                  style: TextStyle(
                                    fontSize: 10.dp,
                                    fontWeight: FontWeight.w400,
                                    color: ColorHelper.neutralLightText,
                                  ),
                                ),
                              ],
                            ),
                          ],
                        ),
                      ),
                    ],
                  ),
                  10.SpaceX,
              const Divider(color: ColorHelper.genericBorderColor,thickness: 0.5,),
              10.SpaceX,
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  RichText(
                    text: TextSpan(
                      text: 'Total ',
                      style: TextStyle(
                        fontSize: 12.dp,
                        fontWeight: FontWeight.w500,
                        color: ColorHelper.neutralDark,
                      ),
                      children: [
                        TextSpan(
                          text: 'Exclusive ',
                          style: TextStyle(
                            fontSize: 12.dp,
                            fontWeight: FontWeight.w500,
                            color: ColorHelper.primaryColor2,
                          ),
                        ),
                        TextSpan(
                          text: 'Rate ${history.isNonDiscounted? '' : '(-${history.discountPercentage ?? 0}%)'}',
                          style: TextStyle(
                            fontSize: 12.dp,
                            fontWeight: FontWeight.w500,
                            color: ColorHelper.neutralDark,
                          ),
                        ),
                      ]
                    ),
                  ),
                  Text(
                    '\$${formatPrice(history.totalDiscountedPrice)}',
                    style: TextStyle(
                      fontSize: 12.dp,
                      fontWeight: FontWeight.w500,
                      color: ColorHelper.neutralDark,
                    ),
                  ),
                ],
              ),
              16.SpaceX,
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  RichText(
                    text: TextSpan(
                      text: 'Total ',
                      style: TextStyle(
                        fontSize: 12.dp,
                        fontWeight: FontWeight.w500,
                        color: ColorHelper.neutralDark,
                      ),
                      children: [
                        TextSpan(
                          text: 'Standard ',
                          style: TextStyle(
                            fontSize: 12.dp,
                            fontWeight: FontWeight.w500,
                            color: ColorHelper.neutralLightText,
                          ),
                        ),
                        TextSpan(
                          text: 'Rate',
                          style: TextStyle(
                            fontSize: 12.dp,
                            fontWeight: FontWeight.w500,
                            color: ColorHelper.neutralDark,
                          ),
                        ),
                      ]
                    ),
                  ),
                  Text(
                    '\$${formatPrice(history.totalOnlinePrice)}',
                    style: TextStyle(
                      fontSize: 12.dp,
                      fontWeight: FontWeight.w500,
                      color: ColorHelper.neutralDark,
                    ),
                  ),
                ],
              ),
              16.SpaceX,
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  RichText(
                    text: TextSpan(
                      text: 'Total ',
                      style: TextStyle(
                        fontSize: 12.dp,
                        fontWeight: FontWeight.w500,
                        color: ColorHelper.neutralDark,
                      ),
                      children: [
                        TextSpan(
                          text: 'Loyalty ',
                          style: TextStyle(
                            fontSize: 12.dp,
                            fontWeight: FontWeight.w500,
                            color: ColorHelper.primaryColor2,
                          ),
                        ),
                        TextSpan(
                          text: 'Rewards',
                          style: TextStyle(
                            fontSize: 12.dp,
                            fontWeight: FontWeight.w500,
                            color: ColorHelper.neutralDark,
                          ),
                        ),
                      ]
                    ),
                  ),
                  Text(
                    '\$ ${ history.isNonDiscounted==true? '0': '${10/*+FlightSearchUtils.mapFlightClass(history.flightClass ?? '').miles*/}'}',
                    style: TextStyle(
                      fontSize: 12.dp,
                      fontWeight: FontWeight.w500,
                      color: ColorHelper.neutralDark,
                    ),
                  ),
                ],
              ),
              10.SpaceX,
              const Divider(color: ColorHelper.genericBorderColor,thickness: 0.5,),
              10.SpaceX,
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  RichText(
                    text: TextSpan(
                      text: 'Total ',
                      style: TextStyle(
                        fontSize: 12.dp,
                        fontWeight: FontWeight.w500,
                        color: ColorHelper.neutralDark,
                      ),
                      children: [
                        TextSpan(
                          text: 'Saved ',
                          style: TextStyle(
                            fontSize: 12.dp,
                            fontWeight: FontWeight.w500,
                            color: ColorHelper.primaryColor2,
                          ),
                        ),
                        TextSpan(
                          text: 'Smart',
                          style: TextStyle(
                            fontSize: 12.dp,
                            fontWeight: FontWeight.w500,
                            color: ColorHelper.neutralDark,
                          ),
                        ),
                      ]
                    ),
                  ),
                  Text(
                    '\$${history.isNonDiscounted == true? 0 : formatPrice((savedSmart - (double.tryParse(history.donationAmount ?? '0')?? 0)).toString())}',
                    style: TextStyle(
                      fontSize: 12.dp,
                      fontWeight: FontWeight.w500,
                      color: ColorHelper.neutralDark,
                    ),
                  ),
                ],
              ),
              16.SpaceX,
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  RichText(
                    text: TextSpan(
                      text: 'Total ',
                      style: TextStyle(
                        fontSize: 12.dp,
                        fontWeight: FontWeight.w500,
                        color: ColorHelper.neutralDark,
                      ),
                      children: [
                        TextSpan(
                          text: 'Shared ',
                          style: TextStyle(
                            fontSize: 12.dp,
                            fontWeight: FontWeight.w500,
                            color: ColorHelper.neutralLightText,
                          ),
                        ),
                        TextSpan(
                          text: 'Smart',
                          style: TextStyle(
                            fontSize: 12.dp,
                            fontWeight: FontWeight.w500,
                            color: ColorHelper.neutralDark,
                          ),
                        ),
                      ]
                    ),
                  ),
                  Text(
                    "\$${formatPrice(history.donationAmount)}",
                    style: TextStyle(
                      fontSize: 12.dp,
                      fontWeight: FontWeight.w500,
                      color: ColorHelper.neutralDark,
                    ),
                  ),
                ],
              ),
              16.SpaceX,
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text(
                    'Shared Transaction Hash',
                    style: TextStyle(
                      fontSize: 10.dp,
                      fontWeight: FontWeight.w400,
                      color: ColorHelper.neutralLightText,
                    ),
                  ),
                  Text(
                    '\$0',
                    style: TextStyle(
                      fontSize: 10.dp,
                      fontWeight: FontWeight.w400,
                      color: ColorHelper.neutralLightText,
                    ),
                  ),
                ],
              ),
              16.SpaceX,
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  RichText(
                    text: TextSpan(
                      text: 'Total ',
                      style: TextStyle(
                        fontSize: 12.dp,
                        fontWeight: FontWeight.w500,
                        color: ColorHelper.neutralDark,
                      ),
                      children: [
                        TextSpan(
                          text: 'Spend ',
                          style: TextStyle(
                            fontSize: 12.dp,
                            fontWeight: FontWeight.w500,
                            color: ColorHelper.primaryColor2,
                          ),
                        ),
                        TextSpan(
                          text: 'Smart',
                          style: TextStyle(
                            fontSize: 12.dp,
                            fontWeight: FontWeight.w500,
                            color: ColorHelper.neutralDark,
                          ),
                        ),
                      ]
                    ),
                  ),
                  Text(
                    '\$${formatPrice(((double.tryParse(history.totalDiscountedPrice ?? '0') ?? 0) + (double.tryParse(history.donationAmount ?? '0')?? 0)).toString())}',
                    style: TextStyle(
                      fontSize: 12.dp,
                      fontWeight: FontWeight.w500,
                      color: ColorHelper.neutralDark,
                    ),
                  ),
                ],
              ),
              if(history.bookingStatus == BookingStatus.pendingPayment || history.isPendingRate || history.isRateConfirmed || ((history.isDiscountedFlight?? false) && history.isRoundTrip && (history.bookingStatus == BookingStatus.paymentFailed)))
              Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  10.SpaceX,
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Row(
                            children: [
                              Text(
                                'Pay by Debit/Credit Card fee: 2.9% ',
                                style: TextStyle(
                                  fontSize: 10.dp,
                                  fontWeight: FontWeight.w400,
                                  color: ColorHelper.neutralLightText,
                                ),
                              ),
                              20.SpaceY,
                              Text(
                                '${controller.currency} ${((controller.totalDiscountedAmount) * (1 + (2.9 / 100))).price}',
                                style: TextStyle(
                                  fontSize: 10.dp,
                                  fontWeight: FontWeight.w400,
                                  color: ColorHelper.neutralLightText,
                                ),
                              ),
                            ],
                          ),
                          Row(
                            children: [
                              Text(
                                'Pay by Cryptocurrency fee: 0% ',
                                style: TextStyle(
                                  fontSize: 10.dp,
                                  fontWeight: FontWeight.w400,
                                  color: ColorHelper.neutralLightText,
                                ),
                              ),
                              39.SpaceY,
                              Text(
                                '${controller.currency} ${controller.totalDiscountedAmount.price}',
                                style: TextStyle(
                                  fontSize: 10.dp,
                                  fontWeight: FontWeight.w400,
                                  color: ColorHelper.neutralLightText,
                                ),
                              ),
                            ],
                          ),
                        ],
                      ),
                      InkWell(
                        onTap: history.isPendingRate ? null : () {
                          if (history.isRateConfirmed || ((history.isDiscountedFlight?? false) && history.isRoundTrip && (history.bookingStatus == BookingStatus.paymentFailed))) {
                            controller.goToPayment(history);
                          } else if (history.bookingStatus != BookingStatus.bookingConfirmed) {
                            debugPrint('## Counter ${controller.counter[history.id]}');
                            if(controller.counter[history.id]!=0){
                              debugPrint('## Inside ${controller.counter[history.id]}');
                              controller.goToPayment(history);
                            }else{
                              CustomFlashWidget.showFlashMessage(
                              type: FlashType.info,
                              title: 'Warning',
                              message: 'Your booking has expired',
                            );
                            }
                          } else {
                            CustomFlashWidget.showFlashMessage(
                              type: FlashType.info,
                              title: 'Warning',
                              message: 'Booking is already Confirmed',
                            );
                            // DefaultSnackbar.show(
                            //     'Warning', 'Booking is already Confirmed');
                          }
                        },
                        child: Container(
                        alignment: Alignment.center,
                        padding: const EdgeInsets.symmetric(horizontal: 8,vertical: 6),
                        // width: 111.dp,
                        height: 32.dp,
                        decoration: BoxDecoration(
                          color: history.isPendingRate
                              ? ColorHelper.genericBorderColor
                              : ColorHelper.primaryColor1,
                          borderRadius: BorderRadius.circular(4),
                        ),
                        child: Text(
                          'Pay Now',
                          style: TextStyle(
                            fontSize: 14,
                            fontWeight: FontWeight.w500,
                            color: history.isPendingRate
                                ? ColorHelper.primaryColor1.withOpacity(0.5)
                                : ColorHelper.white,
                          ),
                        ),
                                              ),
                      ),
                    ],
                  ),
                ],
              ),
              if(history.bookingStatus == BookingStatus.saved)
              Padding(
                padding: const EdgeInsets.only(top: 10),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.end,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [

                    InkWell(
                      onTap: () {
                        controller.goToPayment(history,);
                      },
                      child: Container(
                      alignment: Alignment.center,
                      padding: const EdgeInsets.symmetric(horizontal: 8,vertical: 6),
                      // width: 111.dp,
                      height: 32.dp,
                      decoration: BoxDecoration(
                        color: history.isPendingRate
                            ? ColorHelper.genericBorderColor
                            : ColorHelper.primaryColor1,
                        borderRadius: BorderRadius.circular(4),
                      ),
                      child: Text(
                        'Request Rate',
                        style: TextStyle(
                          fontSize: 14,
                          fontWeight: FontWeight.w500,
                          color: history.isPendingRate
                              ? ColorHelper.primaryColor1.withOpacity(0.5)
                              : ColorHelper.white,
                        ),
                      ),
                    ),
                  ),
                  ],
                ),
              ),
              10.SpaceX,
              const Divider(color: ColorHelper.genericBorderColor,thickness: 0.5,),
              10.SpaceX,
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text(
                    'Status',
                    style: TextStyle(
                      fontSize: 12.dp,
                      fontWeight: FontWeight.w500,
                      color: ColorHelper.neutralDark,
                    ),
                  ),
                  Text(
                    history.bookingStatus.text,
                    style: TextStyle(
                      fontSize: 12.dp,
                      fontWeight: FontWeight.w500,
                      color: history.bookingStatus.textColor,
                    ),
                  ),
                ],
              ),
              12.SpaceX,
              if (history.isNonDiscounted)
                if (history.bookingStatus == BookingStatus.paid ||
                    history.bookingStatus ==
                        BookingStatus.bookingConfirmed ||
                    history.bookingStatus ==
                        BookingStatus.bookingConfirmed)
                  Container(
                    padding: const EdgeInsets.symmetric(
                        horizontal: 16, vertical: 12),
                    decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.circular(8),
                      border: Border.all(
                          color: ColorHelper.blue_tint, width: 0.5),
                    ),
                    child: Row(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text(
                          'Cancellation',
                          style: TextStyle(
                            fontSize: 12.dp,
                            fontWeight: FontWeight.w500,
                            color: ColorHelper.neutralDark,
                          ),
                        ),
                        InkWell(
                          onTap: () {
                            controller.cancelBooking(history);
                          },
                          child: Container(
                            alignment: Alignment.center,
                            padding: const EdgeInsets.symmetric(
                                horizontal: 8, vertical: 6),
                            // width: 111.dp,
                            height: 32.dp,
                            decoration: BoxDecoration(
                              color: ColorHelper.primaryColor1,
                              borderRadius: BorderRadius.circular(4),
                            ),
                            child: const Text(
                              'Cancel Booking',
                              style: TextStyle(
                                fontSize: 14,
                                fontWeight: FontWeight.w500,
                                color: ColorHelper.white,
                              ),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ],
          ),
        ],
      );
    });
  });
}