sellThruAssetsModalBottomSheet method

void sellThruAssetsModalBottomSheet(
  1. dynamic context,
  2. String transferOrderId,
  3. String filterProductCode
)

Implementation

void sellThruAssetsModalBottomSheet(
  context,
  String transferOrderId,
  String filterProductCode,
) {
  final Localization localization = Localization.getInstance();
  final SellThruHistoryController controller =
      Get.put(SellThruHistoryController());
  final ScrollController scrollController = ScrollController();
  int currentCompletedPage = 1;
  String? query;
  TextEditingController searchController = TextEditingController();
  bool searchSubmitted = false;
  final GlobalKey<RefreshIndicatorState> _refreshIndicatorKey =
      GlobalKey<RefreshIndicatorState>();

  Future<void> _refresh() async {
    currentCompletedPage = 0;
    controller.callSellthruHistoryAssetApi(
      transferOrderId,
      filterProductCode,
      currentCompletedPage,
      context,
      query: "",
    );
  }

  void onScroll() {
    if (scrollController.position.extentAfter < 300 &&
        !controller.isLoadingMore.value &&
        controller.searchedSellThruAssetList.length <
            controller.totalAssets) {
      controller.isLoadingMore.value = true;
      currentCompletedPage += 1; // Assuming each page has 10 items
      controller.callSellthruHistoryAssetApi(
        transferOrderId,
        filterProductCode,
        currentCompletedPage,
        context,
        query: query,
      );
    }
  }

  searchedList() {
    ConditionalLogs().customLog("$query");
    currentCompletedPage = 1;
    controller.callSellthruHistoryAssetApi(
      transferOrderId,
      filterProductCode,
      currentCompletedPage,
      context,
      query: query,
    );
  }

  scrollController.addListener(onScroll);
  showModalBottomSheet(
    enableDrag: false,
    context: context,
    isScrollControlled: true,
    isDismissible: true,
    backgroundColor: Colors.transparent,
    shape: RoundedRectangleBorder(
      borderRadius: BorderRadius.circular(
        SizeConstant.getHeightWithScreen(20),
      ),
    ),
    builder: (BuildContext ctx) {
      return Container(
        decoration: BoxDecoration(
          color: ColorConstant.white,
          borderRadius: BorderRadius.only(
            topLeft: Radius.circular(SizeConstant.getHeightWithScreen(20)),
            topRight: Radius.circular(SizeConstant.getHeightWithScreen(20)),
          ),
        ),
        height: SizeConstant.getHeightWithScreen(593),
        padding: EdgeInsets.only(
          left: SizeConstant.getHeightWithScreen(16),
          top: SizeConstant.getHeightWithScreen(26),
          right: SizeConstant.getHeightWithScreen(16),
        ),
        child: Column(
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Text(
                  localization.translate("scannedAssets"),
                  style: TextStyle(
                    color: ColorConstant.black12,
                    fontSize: SizeConstant.largeFont,
                    fontWeight: FontWeight.w500,
                  ),
                ),
                GestureDetector(
                  onTap: () {
                    Helper.close();
                  },
                  child: Image.asset(
                    "assets/images/close.png",
                    package: Constants.packageName,
                    height: SizeConstant.getHeightWithScreen(28),
                    width: SizeConstant.getHeightWithScreen(28),
                  ),
                ),
              ],
            ),
            SizedBox(
              height: SizeConstant.getHeightWithScreen(12),
            ),
            // ProductDetailCard(
            //   productName: productDetail.productName ?? "-",
            //   description: productDetail.productCode ?? "-",
            //   scannedCount: productDetail.count ?? 0,
            //   unitPrice: productDetail.unitPrice != null
            //       ? "${helper.Helper.amountWithCurrency(productDetail.currency ?? "USD", productDetail.unitPrice!)}/${"unit".tr}"
            //       : "-",
            //   totalPrice: productDetail.totalPrice != null
            //       ? helper.Helper.amountWithCurrency(
            //           productDetail.currency ?? "USD",
            //           productDetail.totalPrice!,
            //         )
            //       : "-",
            // ),
            // SizedBox(
            //   height: SizeConstant.getHeightWithScreen(19),
            // ),
            SearchBarWidget(
              padding: EdgeInsets.zero,
              controller: searchController,
              textInputAction: TextInputAction.search,
              textInputType: TextInputType.phone,
              hintText: localization.translate("search"),
              inputFormatters: [
                FilteringTextInputFormatter.allow(RegExp(r'[0-9]'))
              ],
              onSubmit: (text) {
                if (query == null) {
                  return;
                } else if (query!.isEmpty) {
                  return;
                }
                searchSubmitted = true;
                Helper.hideKeyboard();
                searchedList();
              },
              onChanged: (text) {
                query = text;
                if (query != null && query!.isEmpty && searchSubmitted) {
                  searchSubmitted = false;
                  Helper.hideKeyboard();
                  searchedList();
                }
              },
              borderColor: ColorConstant.shadowColor,
              prefixIcon: GestureDetector(
                onTap: () {
                  if (searchSubmitted) {
                    searchController.text = "";
                    query = "";
                    searchSubmitted = false;
                    Helper.hideKeyboard();
                    searchedList();
                  } else {
                    Helper.hideKeyboard();
                    searchController.text = "";
                    query = "";
                  }
                },
                child: Container(
                  color: Colors.transparent,
                  padding: EdgeInsets.only(
                    left: SizeConstant.getHeightWithScreen(10),
                    right: SizeConstant.getHeightWithScreen(10),
                  ),
                  child: Image.asset(
                    "assets/images/back_arrow.png",
                    package: Constants.packageName,
                    height: SizeConstant.getHeightWithScreen(13),
                    width: SizeConstant.getHeightWithScreen(13),
                  ),
                ),
              ),
              suffixIcon: GestureDetector(
                onTap: () {
                  if (query == null) {
                    return;
                  } else if (query!.isEmpty) {
                    return;
                  }
                  searchSubmitted = true;
                  Helper.hideKeyboard();
                  searchedList();
                },
                child: Container(
                  color: Colors.transparent,
                  padding: EdgeInsets.only(
                    left: SizeConstant.getHeightWithScreen(10),
                    right: SizeConstant.getHeightWithScreen(10),
                  ),
                  child: SvgPicture.asset(
                    "assets/images/search.svg",
                    package: Constants.packageName,
                    height: SizeConstant.getHeightWithScreen(13),
                    width: SizeConstant.getHeightWithScreen(13),
                  ),
                ),
              ),
            ),
            SizedBox(
              height: SizeConstant.getHeightWithScreen(19),
            ),
            Padding(
              padding: EdgeInsets.symmetric(
                // vertical: SizeConstant.getHeightWithScreen(10),
                horizontal: SizeConstant.getHeightWithScreen(15),
              ),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Expanded(
                    child: Text(
                      localization.translate("serialNumber"),
                      style: TextStyle(
                        color: ColorConstant.black2,
                        fontSize: SizeConstant.smallFont,
                        fontWeight: FontWeight.w500,
                      ),
                    ),
                  ),
                  SizedBox(
                    width: SizeConstant.getHeightWithScreen(18),
                  ),
                  SizedBox(
                    width: SizeConstant.getHeightWithScreen(90),
                    child: Text(
                      localization.translate("purchaseDate"),
                      style: TextStyle(
                        color: ColorConstant.black2,
                        fontSize: SizeConstant.smallFont,
                        fontWeight: FontWeight.w500,
                      ),
                    ),
                  ),
                  SizedBox(
                    width: SizeConstant.getHeightWithScreen(18),
                  ),
                  SizedBox(
                    width: SizeConstant.getHeightWithScreen(74),
                    child: Text(
                      localization.translate("expiryDate"),
                      style: TextStyle(
                        color: ColorConstant.black2,
                        fontSize: SizeConstant.smallFont,
                        fontWeight: FontWeight.w500,
                      ),
                    ),
                  ),
                ],
              ),
            ),
            SizedBox(
              height: SizeConstant.getHeightWithScreen(9),
            ),
            Obx(
              () => Expanded(
                  child: RefreshIndicator.adaptive(
                color: ColorConstant.primaryColor,
                triggerMode: RefreshIndicatorTriggerMode.anywhere,
                key: _refreshIndicatorKey,
                onRefresh: _refresh,
                child: ListView.separated(
                  itemCount: controller.searchedSellThruAssetList.length + 1,
                  controller: scrollController,
                  itemBuilder: (_, index) {
                    if (index < controller.searchedSellThruAssetList.length) {
                      return Container(
                        padding: EdgeInsets.symmetric(
                          vertical: SizeConstant.getHeightWithScreen(10),
                          horizontal: SizeConstant.getHeightWithScreen(15),
                        ),
                        decoration: BoxDecoration(
                          color: ColorConstant.dividerColor,
                          borderRadius: BorderRadius.circular(
                            SizeConstant.getHeightWithScreen(5),
                          ),
                        ),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Expanded(
                              child: AnimatedTooltip(
                                theme: ThemeData.light(),
                                content: Text(
                                  controller.searchedSellThruAssetList[index]
                                          .serialnumber ??
                                      "-",
                                  style: TextStyle(
                                    color: ColorConstant.black2,
                                    fontSize: SizeConstant.smallFont,
                                    fontWeight: FontWeight.w500,
                                  ),
                                ),
                                child: GestureDetector(
                                  onLongPress: () async {
                                    await Helper.copyToClipBoard(controller
                                        .searchedSellThruAssetList[index]
                                        .serialnumber);
                                  },
                                  child: Text(
                                    controller
                                            .searchedSellThruAssetList[index]
                                            .serialnumber ??
                                        "-",
                                    style: TextStyle(
                                      color: ColorConstant.black2,
                                      overflow: TextOverflow.ellipsis,
                                      fontSize: SizeConstant.smallFont,
                                      fontWeight: FontWeight.w500,
                                    ),
                                  ),
                                ),
                              ),
                            ),
                            SizedBox(
                              width: SizeConstant.getHeightWithScreen(18),
                            ),
                            SizedBox(
                              width: SizeConstant.getHeightWithScreen(90),
                              child: Text(
                                controller.searchedSellThruAssetList[index]
                                            .purchaseDate !=
                                        null
                                    ? formatDate(
                                        controller
                                            .searchedSellThruAssetList[index]
                                            .purchaseDate,
                                        'dd-MM-yyyy',
                                        'dd MMM yyyy',
                                      )
                                    : "-",
                                style: TextStyle(
                                  color: ColorConstant.grey32,
                                  overflow: TextOverflow.ellipsis,
                                  fontSize: SizeConstant.xSmallFont,
                                  fontWeight: FontWeight.w500,
                                ),
                              ),
                            ),
                            SizedBox(
                              width: SizeConstant.getHeightWithScreen(18),
                            ),
                            SizedBox(
                              width: SizeConstant.getHeightWithScreen(74),
                              child: Text(
                                controller.searchedSellThruAssetList[index]
                                            .expiryDate !=
                                        null
                                    ? formatDate(
                                        controller
                                            .searchedSellThruAssetList[index]
                                            .expiryDate!,
                                        'yyyy-MM-dd HH:mm:ss',
                                        'dd MMM yyyy',
                                      )
                                    : "-",
                                style: TextStyle(
                                  color: ColorConstant.grey32,
                                  overflow: TextOverflow.ellipsis,
                                  fontSize: SizeConstant.xSmallFont,
                                  fontWeight: FontWeight.w500,
                                ),
                              ),
                            ),
                          ],
                        ),
                      );
                    } else {
                      return controller.searchedSellThruAssetList.length <
                              controller.totalAssets
                          ? const Center(
                              child: CircularProgressIndicator.adaptive())
                          : const SizedBox();
                    }
                  },
                  separatorBuilder: (_, index) {
                    return SizedBox(
                      height: SizeConstant.getHeightWithScreen(9),
                    );
                  },
                ),
              )),
            )
          ],
        ),
      );
    },
  );
}