如何flutter getx制作13个不同的带搜索功能的控制器

问题描述 投票:0回答:2
class IlacProductController extends GetxController {
  final IlacProductRepo ilacProductRepo;
  IlacProductController({required this.ilacProductRepo});
  List<dynamic> _ilacproductList = [];
  List<dynamic> get ilacproductList => _ilacproductList;

  bool _isLoaded = false;
  bool get isLoaded => _isLoaded ;

  Future<void> getIlacProductList() async {
    Response response = await ilacProductRepo.getIlacProductList();
    if (response.statusCode == 200) {
      print("got ilaç");
      _ilacproductList = [];
      _ilacproductList.addAll(Product.fromJson(response.body).products);
      _isLoaded=true;
      update();
    } else {return print("something wrong");}
  }
}

我有13个不同的控制器代码类似于上面的代码,每个代表不同的类别

  @override
  Widget buildResults(BuildContext context) {
    return GetBuilder<HalkSagligiProductController>(builder: (allProduct) {
      return allProduct.isLoaded
          ? ListView.builder(
          shrinkWrap: true,
          physics: const NeverScrollableScrollPhysics(),
          itemCount: allProduct.halksagligiproductList.length,
          itemBuilder: (context, index) {
            return GestureDetector(
              onTap: () {
                Get.toNamed(RouteHelper.getHalkProduct(index));
              },
              child: Container(
                  margin: EdgeInsets.only(
                      left: Dimensions.width20,
                      right: Dimensions.width10,
                      bottom: Dimensions.height15),
                  child: Row(
                    children: [
                      //image section
                      Container(
                        width: Dimensions.listViewImgSize,
                        height: Dimensions.listViewImgSize,
                        decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(
                                Dimensions.radius20),
                            color: Colors.white38,
                            image: DecorationImage(
                                fit: BoxFit.cover,
                                image: CachedNetworkImageProvider(AppConstans
                                    .BASE_URL +
                                    AppConstans.UPLOAD_URL +
                                    allProduct
                                        .halksagligiproductList[index]
                                        .img!))),
                      ),
                      //text section
                      Expanded(
                        child: Container(
                          height: Dimensions.listViewTextContSize,
                          decoration: BoxDecoration(
                              borderRadius: BorderRadius.only(
                                  topRight: Radius.circular(
                                      Dimensions.radius20),
                                  bottomRight: Radius.circular(
                                      Dimensions.radius20)),
                              color: Colors.white),
                          child: Padding(
                            padding: EdgeInsets.only(
                                left: Dimensions.width10,
                                right: Dimensions.width10),
                            child: Column(
                              crossAxisAlignment:
                              CrossAxisAlignment.start,
                              mainAxisAlignment:
                              MainAxisAlignment.center,
                              children: [
                                BigText(
                                  text: allProduct
                                      .halksagligiproductList[index]
                                      .name!,
                                ),
                                SizedBox(
                                  height: Dimensions.height10,
                                ),
                                ExpandableProductText(
                                    text: allProduct
                                        .halksagligiproductList[index]
                                        .description!),
                                SizedBox(
                                  height: Dimensions.height10,
                                ),
                              ],
                            ),
                          ),
                        ),
                      )
                    ],
                  )),
            );
          })
          : const CircularProgressIndicator(
        color: AppColor.mainColor,
      );
    });
  }

在上面的代码中,我使用 getx 提取图像名称和描述。 我的问题是:如何在搜索屏幕上使用 Getx 按名称和描述中的文字搜索 13 个不同的控制器?

android ios flutter dart flutter-getx
2个回答
2
投票
 final searchController = Get.find<SearchController>();

您可以在不同的屏幕中多次使用此功能。


0
投票

声明

final ilacProductController = Get.put(IlacProductController());

进入屏幕并使用对象

ilacProductController
进行访问。

© www.soinside.com 2019 - 2024. All rights reserved.