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 IncommeWidget(
    child: StateBuilder<IncommePaymentMethodController>(
      container: this,
      init: _controller,
      context: context,
      builder: (controller) {
        var data = controller.viewState.value.data ?? SortedPaymentMethod();
        return Column(
          children: [
            PaymentMethodAppBar(controller: _controller),
            Expanded(
              child: ListView(
                physics: const BouncingScrollPhysics(),
                padding: context.mediaQuery.padding.copyWith(
                  top: 0,
                  left: 0,
                  right: 0,
                ),
                children: [
                  Padding(
                    padding: EdgeInsets.symmetric(
                      horizontal: AppSizer.getWidthSizeOf(context, 5),
                    ),
                    child: Text(
                      "payment_method".tl,
                      // "Payment Methods",
                      // style:
                      //     _fontUtils.fontName(FontFamily.poppins).size24.bold(),
                      style: IncommeTextStyle.bodyBold.copyWith(
                        fontSize: 20.sp(context),
                      ),
                    ),
                  ),
                  SizedBox(height: AppSizer.getHeightSizeOf(context, 2)),
                  Obx(() {
                    final state = _controller.viewState.value;
                    return TotalPricePayment(
                      // totalPay: _controller.checkout.total -
                      //     (usePoint ?? 0).toDouble(),
                      totalPay: state.data?.totalFormattedPrice ?? "0",
                      // totalPay: 100000,
                      // totalPay: args?.totalPay ?? 0,
                    );
                  }),
                  Obx(() {
                    final state = _controller.viewState.value;
                    if (state.status.isLoading) {
                      return SizedBox(
                        width: AppSizer.getWidthSizeOf(context, 100),
                        child: ShrinkColumn(
                          children: [
                            SizedBox(height: 3.h(context)),
                            for (int i = 0; i < 5; i++)
                              Container(
                                width: double.infinity,
                                height: 60,
                                margin: const EdgeInsets.symmetric(
                                  horizontal: 16,
                                  vertical: 4,
                                ),
                                decoration: BoxDecoration(
                                  color: Colors.grey,
                                  borderRadius: BorderRadius.circular(4),
                                ),
                                child: Shimmer.fromColors(
                                  baseColor: Colors.grey.shade300,
                                  highlightColor: Colors.grey.shade100,
                                  child: Container(
                                    width: double.infinity,
                                    height: 60,
                                    decoration: BoxDecoration(
                                      color: Colors.grey,
                                      borderRadius: BorderRadius.circular(4),
                                    ),
                                  ),
                                ),
                              ),
                          ],
                        ),
                      );
                    } else {
                      return ShrinkColumn(
                        children: [
                          SizedBox(
                            height: AppSizer.getHeightSizeOf(context, 1.5),
                          ),
                          if (data.vybeChannels.isNotEmpty == true)
                            ExpansionPaymentMethod(
                              channels: [...(data.vybeChannels)],
                              title: "E-Wallet",
                              onTap: (val) {
                                if (val.code == "VYBE-PG") {
                                  if (val.paymentUrl.isNotEmpty) {
                                    if (onProcess != null) {
                                      onProcess!(
                                        CheckoutPayment(
                                          vybeResult: PaymentVybeResult(
                                            url: Uri.parse(val.paymentUrl),
                                            orderGroupID: orderGroupID,
                                            channelCode: val.code,
                                            channelName: val.name,
                                            total: data.totalPrice,
                                          ),
                                        ),
                                      );
                                    } else {
                                      Get.toNamed(
                                        IncommeConstants.appRoute.paymentVybe,
                                        arguments: PaymentVybeArg(
                                          callBackRouteName:
                                              callBackRouteName,
                                          paymentResult: PaymentVybeResult(
                                            url: Uri.parse(val.paymentUrl),
                                            orderGroupID: orderGroupID,
                                            channelCode: val.code,
                                            channelName: val.name,
                                            total: data.totalPrice,
                                            // amount: args?.totalPay ?? 0,
                                            // orderItems: args?.orderItems ?? [],
                                            // pointUsed: args?.pointUsed ?? 0,
                                            // ! GET FROM CART
                                            // amount: 100000,
                                            // orderItems: [],
                                            // pointUsed: 0,
                                            // amount: _controller.checkout.total,
                                            // orderItems:
                                            //     _controller
                                            //         .checkout
                                            //         .getDataListRequest,
                                            // pointUsed: usePoint,
                                          ),
                                        ),
                                      );
                                    }
                                  } else {
                                    if (onError != null) {
                                      onError!("failed_get_url".tl);
                                    } else {
                                      showDTSnackBarError(
                                        context,
                                        "failed_get_url".tl,
                                      );
                                    }
                                  }
                                } else if (val.code.toLowerCase().contains(
                                  "qris",
                                )) {
                                  _controller.checkoutPaymentQris(
                                    CheckoutPaymentReq(
                                      channelCode: val.code,
                                      channelName: val.name,
                                      totalPrice:
                                          state.data?.totalPrice ?? "0",
                                      // amount: args?.totalPay ?? 0,
                                      orderGroupId: orderGroupID,
                                      // orderItems: args?.orderItems,
                                      // pointUsed: args?.pointUsed,
                                    ),
                                  );
                                }
                              },
                            ),
                          if (data.codChannels.isNotEmpty == true)
                            ExpansionPaymentMethod(
                              channels: [...(data.codChannels)],
                              title: "in_person_payment".tl,
                              // title: "In-person Payment",
                              onTap: (val) {
                                // onProcess?.call(
                                //   CheckoutPayment(),
                                // );
                                _controller.checkoutPaymentInPerson(
                                  CheckoutPaymentReq(
                                    channelCode: val.code,
                                    channelName: val.name,
                                    totalPrice: state.data?.totalPrice ?? "0",
                                    // amount: args?.totalPay ?? 0,
                                    orderGroupId: orderGroupID,
                                    // orderItems: args?.orderItems,
                                    // pointUsed: args?.pointUsed,
                                  ),
                                );
                              },
                            ),
                          if (data.vaChannels.isNotEmpty == true)
                            ExpansionPaymentMethod(
                              channels: data.vaChannels,
                              title: "transfer_va".tl.toUpperCase(),
                              // title: "VA Transfer",
                              onTap: (val) {
                                // onProcess?.call(
                                //   CheckoutPayment(),
                                // );
                                _controller.checkPaymentPG(
                                  CheckoutPaymentReq(
                                    channelCode: val.code,
                                    channelName: val.name,
                                    totalPrice: state.data?.totalPrice ?? "0",
                                    // amount: args?.totalPay ?? 0,
                                    orderGroupId: orderGroupID,
                                    // orderItems: args?.orderItems,
                                    // pointUsed: args?.pointUsed,
                                  ),
                                );
                              },
                              // showButtomSheetCouponInvalid(context),
                            ),
                          if (controller
                                  .viewState
                                  .value
                                  .data
                                  ?.instantChannels
                                  .isNotEmpty ==
                              true)
                            ExpansionPaymentMethod(
                              channels:
                                  controller
                                      .viewState
                                      .value
                                      .data!
                                      .instantChannels,
                              title: "instant_payment".tl.toUpperCase(),
                              // title: "Instant Payment",
                              onTap: (val) {
                                // onProcess?.call(
                                //   CheckoutPayment(),
                                // );
                                if (val.code.toLowerCase().contains(
                                  "webview",
                                )) {
                                  _controller.checkoutPaymentCC(
                                    CheckoutPaymentReq(
                                      channelCode: val.code,
                                      channelName: val.name,
                                      totalPrice:
                                          state.data?.totalPrice ?? "0",
                                      // amount: args?.totalPay ?? 0,
                                      orderGroupId: orderGroupID,
                                      // orderItems: args?.orderItems,
                                      // pointUsed: args?.pointUsed,
                                    ),
                                  );
                                }
                                // _controller.checkoutPaymentQris(
                                //   CheckoutPaymentReq(
                                //     channelCode: val.code,
                                //     channelName: val.name,
                                //     totalPrice:
                                //         state.data?.totalPrice ?? "0",
                                //     // amount: args?.totalPay ?? 0,
                                //     orderGroupId:
                                //         orderGroupID,
                                //     // orderItems: args?.orderItems,
                                //     // pointUsed: args?.pointUsed,
                                //   ),
                                // );
                              },
                            ),
                          if (data.creditChannels.isNotEmpty == true ||
                              data.debitChannels.isNotEmpty == true)
                            ExpansionPaymentMethod(
                              channels: [
                                ...(data.creditChannels),
                                ...(data.debitChannels),
                              ],
                              title: "card_cc_debit".tl.toUpperCase(),
                              // title: "Credit Card Debit",
                              onTap: (val) {
                                // onProcess?.call(
                                //   CheckoutPayment(),
                                // );
                                _controller.checkoutPaymentCC(
                                  CheckoutPaymentReq(
                                    channelCode: val.code,
                                    channelName: val.name,
                                    totalPrice: state.data?.totalPrice ?? "0",
                                    // amount: args?.totalPay ?? 0,
                                    orderGroupId: orderGroupID,
                                    // orderItems: args?.orderItems,
                                    // pointUsed: args?.pointUsed,
                                  ),
                                );
                              },
                            ),
                          if (!state.status.isInitial &&
                              controller.isAllEmpty())
                            ShrinkColumn(
                              children: [
                                SizedBox(height: (12.5).h(context)),
                                Padding(
                                  padding: const EdgeInsets.symmetric(
                                    vertical: 12,
                                  ),
                                  child: SvgColorGrader.asset(
                                    path:
                                        Assets
                                            .icons
                                            .illustration
                                            .paymentEmpty
                                            .path,
                                  ),
                                  // child:
                                  //     Assets
                                  //         .images
                                  //         .illustration
                                  //         .paymentEmpty
                                  //         .image(),
                                ),
                                Text(
                                  "no_payment_method_found".tl,
                                  // "No Payment Method found",
                                  textAlign: TextAlign.center,
                                  // style:
                                  //     _fontUtils
                                  //         .fontName(FontFamily.poppins)
                                  //         .fixedSize(14)
                                  //         .semiBold(),
                                  style: IncommeTextStyle.bodyMedium.copyWith(
                                    fontSize: 14,
                                  ),
                                ),
                              ],
                            ),
                        ],
                      );
                    }
                  }),
                ],
              ),
            ),
          ],
        );
      },
    ),
  );
}