title: Flutter: How to Query List Items using GetX
body: <p>I am trying to filter according to the category but it's displaying all products on each category page, but I want to filter according to the category page, please check my code and let me know how I can do it.</p>
  <pre><code>class CategoryNavigationController extends GetxController {
  
    final List&lt;CategoryModel&gt; _categories = allCategories;
  
    List&lt;CategoryModel&gt; get allCategory =&gt; _categories;
  
    int currentCategoryIndex;
    String currentCategoryTitle;
    List&lt;Widget&gt; totalCategoryTabs = [];
    List&lt;ProductModel&gt; _filtertedProducts;
    Widget currentTab;
  
    @override
    void onInit() {
      super.onInit();
      totalCategoryTabs = List.generate(allCategory.length, (index) {
        return ProductCardList(
          totalProducts: 1,
          productName: &quot;WHy&quot;,
          productImage: &quot;assets/images/chicken.png&quot;,
          price: &quot;150&quot;,
          scrollDirection: Axis.vertical,
        );
      });
    }
  
    void selectCategory(int index) {
      currentCategoryIndex = index;
      currentCategoryTitle = allCategory[index].categoryName;
      _filterProductData(currentCategoryTitle);
      currentTab = totalCategoryTabs[index];
      Get.to(() =&gt; CategoryScreen());
      update();
    }
  
    void changeTab(int index) {
      currentCategoryIndex = index;
      currentCategoryTitle = allCategory[currentCategoryIndex].categoryName;
      _filterProductData(currentCategoryTitle);
      currentTab = totalCategoryTabs[currentCategoryIndex];
      update();
    }
  
    void _filterProductData(query) {
      print(query);
    }
  }
  </code></pre>
  <p>Here is my data model. I want to rebuild my current TabView every time when user drag tab view or tap on the tab button</p>
  <pre><code>class CategoryModel {
    String categoryName;
    String categoryImage;
    String categoryIcon;
  
    CategoryModel({
      this.categoryName,
      this.categoryImage,
      this.categoryIcon,
    });
  }
  
  List&lt;CategoryModel&gt; allCategories = &lt;CategoryModel&gt;[
    CategoryModel(
      categoryName: &quot;Chicken&quot;,
      categoryImage: &quot;assets/images/chicken.png&quot;,
      categoryIcon: &quot;assets/svg/chicken.svg&quot;,
    ),
    CategoryModel(
      categoryName: &quot;Fish&quot;,
      categoryImage: &quot;assets/images/sea_fish.png&quot;,
      categoryIcon: &quot;assets/svg/fish.svg&quot;,
    ),
    CategoryModel(
      categoryName: &quot;Mutton&quot;,
      categoryImage: &quot;assets/images/mutton.png&quot;,
      categoryIcon: &quot;assets/svg/mutton.svg&quot;,
    ),
    CategoryModel(
      categoryName: &quot;Marinade&quot;,
      categoryImage: &quot;assets/images/marinade.png&quot;,
      categoryIcon: &quot;assets/svg/premium_meat.svg&quot;,
    ),
    CategoryModel(
      categoryName: &quot;Cold Cut&quot;,
      categoryImage: &quot;assets/images/sea_fish.png&quot;,
      categoryIcon: &quot;assets/svg/cold_cut.svg&quot;,
    ),
    CategoryModel(
      categoryName: &quot;Prone&quot;,
      categoryImage: &quot;assets/images/sea_fish.png&quot;,
      categoryIcon: &quot;assets/svg/fish.svg&quot;,
    ),
  ];
  
  class ProductModel {
    String productName;
    String productImage;
    CategoryModel category;
    String price;
    String stock;
  
    ProductModel({
      this.productName,
      this.category,
      this.price,
      this.stock,
      this.productImage,
    });
  }
  
  List&lt;ProductModel&gt; allProducts = &lt;ProductModel&gt;[
    ProductModel(
      category: allCategories[0],
      productName: &quot;chicken1&quot;,
      productImage: &quot;assets/images/chicken.png&quot;,
      price: &quot;150&quot;,
    ),
    ProductModel(
      category: allCategories[0],
      productName: &quot;chicken2&quot;,
      productImage: &quot;assets/images/chicken.png&quot;,
      price: &quot;150&quot;,
    ),
    ProductModel(
      category: allCategories[1],
      productName: &quot;fish1&quot;,
      productImage: &quot;assets/images/fish.png&quot;,
      price: &quot;150&quot;,
    ),
    ProductModel(
      category: allCategories[1],
      productName: &quot;fish2&quot;,
      productImage: &quot;assets/images/fish.png&quot;,
      price: &quot;150&quot;,
    ),
    ProductModel(
      category: allCategories[2],
      productName: &quot;mutton1&quot;,
      productImage: &quot;assets/images/mutton.png&quot;,
      price: &quot;150&quot;,
    ),
    ProductModel(
      category: allCategories[2],
      productName: &quot;mutton2&quot;,
      productImage: &quot;assets/images/mutton.png&quot;,
      price: &quot;150&quot;,
    ),
    ProductModel(
      category: allCategories[3],
      productName: &quot;marinade1&quot;,
      productImage: &quot;assets/images/marinade.png&quot;,
      price: &quot;150&quot;,
    ),
    ProductModel(
      category: allCategories[3],
      productName: &quot;marinade2&quot;,
      productImage: &quot;assets/images/marinade.png&quot;,
      price: &quot;150&quot;,
    ),
    ProductModel(
      category: allCategories[4],
      productName: &quot;ColdCut1&quot;,
      productImage: &quot;assets/images/sea_fish.png&quot;,
      price: &quot;150&quot;,
    ),
    ProductModel(
      category: allCategories[4],
      productName: &quot;ColdCut2&quot;,
      productImage: &quot;assets/images/sea_fish.png&quot;,
      price: &quot;150&quot;,
    ),
    ProductModel(
      category: allCategories[5],
      productName: &quot;prone1&quot;,
      productImage: &quot;assets/images/sea_fish.png&quot;,
      price: &quot;150&quot;,
    ),
    ProductModel(
      category: allCategories[5],
      productName: &quot;prone2&quot;,
      productImage: &quot;assets/images/sea_fish.png&quot;,
      price: &quot;150&quot;,
    ),
  ];
  </code></pre>
  <p>This is my Category screen, Where I use TabBar &amp; TabView.</p>
  <pre><code>GetBuilder&lt;CategoryNavigationController&gt;(
        builder: (controller) =&gt; Scaffold(
          appBar: AppBar(
            toolbarHeight: AppConfig.screenHeight(context) * 0.06,
            centerTitle: true,
            elevation: 0,
            backgroundColor: Colors.white,
            title: Text(
              &quot;MENU&quot;,
              style: TextStyle(
                color: Color(0xff1F1F1F),
                fontWeight: FontWeight.w600,
                fontStyle: FontStyle.normal,
              ),
            ),
          ),
          body: DefaultTabController(
            initialIndex: controller.currentCategoryIndex,
            length: controller.allCategory.length,
            child: Container(
              width: double.infinity,
              height: double.infinity,
              child: Column(
                children: [
                  Container(
                    height: AppConfig.screenHeight(context) * 0.1,
                    decoration: BoxDecoration(
                      border: Border(
                        bottom: BorderSide(
                          color: AppConfig.disableColor,
                          width: 1,
                        ),
                      ),
                      boxShadow: [
                        BoxShadow(
                          color: AppConfig.disableColor.withOpacity(0.5),
                          offset: Offset(0, 1),
                          spreadRadius: 1,
                          blurRadius: 1,
                        ),
                      ],
                      color: Colors.white,
                    ),
                    child: TabBar(
                      controller: controller.tabController,
                      onTap: (index) {
                        controller.changeTab();
                      },
                      isScrollable: true,
                      indicator: BoxDecoration(
                        color: AppConfig.disableColor,
                        border: Border(
                          bottom: BorderSide(
                            color: AppConfig.primaryColor,
                          ),
                        ),
                      ),
                      tabs: List.generate(
                        controller.allCategory.length,
                        (index) {
                          return CategoryButtons(
                            buttonIcon: SvgPicture.asset(
                              controller.allCategory[index].categoryIcon,
                              width: AppConfig.screenWidth(context) * 0.085,
                            ),
                            buttonName:
                                controller.allCategory[index].categoryName,
                          );
                        },
                      ),
                    ),
                  ),
                  Expanded(
                    child: TabBarView(
                      controller: controller.tabController,
                      children:
                          controller.allCategory.map((CategoryModel category) {
                        return controller.currentTab;
                      }).toList(),
                    ),
                  ),
                ],
              ),
            ),
          ),
        ),
      );
  </code></pre>