Get List Not Updated

Viewed 20

I have a problem with my ListView using Getx. I have a list with the data from Firestore. But the problem is, after visit the screen I can move out the page to another page, but when I return to the page with that list, the same data display in the list view 02 times, or 03 times, that depend of the number time I close and open the List screen .... Please can you look my code below :

                            init: SubCategoryController(),
                            builder: (controller) =>
                                Container(
                                  height: 90,
                                  //width: 100,
                                  child: ListView.builder(
                                      itemCount: controller.subCategoryModel
                                          .length,
                                      scrollDirection: Axis.horizontal,
                                      itemBuilder: (context, index) {
                                        return Padding(
                                            padding: const EdgeInsets.all(8.0),
                                            child: InkWell(
                                              onTap: () {
                                             

                                              },
                                              child: Container(
                                                width: 90,
                                                decoration: BoxDecoration(
                                                    borderRadius: BorderRadius
                                                        .circular(10),
                                                    border: Border.all(
                                                        color: Colors.grey)
                                                ),
                                                child: Column(
                                                  mainAxisAlignment: MainAxisAlignment
                                                      .spaceAround,
                                                  children: [
                                                    Container(
                                                      height: 50,
                                                      width: 70,
                                                      child: Center(
                                                          child: Image.network(
                                                            controller
                                                                .subCategoryModel[index]
                                                                .scatLogo
                                                                .toString(),
                                                            fit: BoxFit.fill,)),
                                                    ),
                                                    Expanded(child: CustomText(
                                                        text: controller
                                                            .subCategoryModel[index]
                                                            .scatName
                                                            .toString(),
                                                        fontSeize: 12,
                                                        color: Colors.grey,
                                                        alignment: Alignment
                                                            .center,
                                                        fontWeight: FontWeight
                                                            .bold))
                                                  ],
                                                ),
                                              ),
                                            )
                                        );
                                      }),
                                ),
class SubCategoryController extends GetxController{
 //String? catRef;


  ValueNotifier<bool> _loading = ValueNotifier(false);
  ValueNotifier<bool> get loading => _loading;

  List<SubCategoryModel> get subCategoryModel => subCat;
  List<SubCategoryModel> subCat = [];


  final CollectionReference _subCategoryCollectionRef = FirebaseFirestore.instance.collection("TypesFoods").doc("raw")
      .collection("raw");

  // SubCategoryController(catRef){
  //   getCategory(catRef);
  // }

  SubCategoryController(){
    presentSubCat(CatScatRef);
  }
  var CatScatRef;
  presentSubCat(var CatRefTrans){
    CatScatRef = CatRefTrans;
    getCategory(CatScatRef);
  }

  getCategory(catRef)async{
    _loading.value = true;
    _subCategoryCollectionRef.doc('chicken').collection('chicken').get().then((value){
      for(int i = 0; i< value.docs.length; i++){
        subCat.add(SubCategoryModel.fromJson(value.docs[i].data()));
        _loading.value = false;
      }
      update();
    });
  }


  
  @override
  void onReady() {
    super.onReady();
  }
  @override
  void onInit() {
    super.onInit();
  }




}
                          ),```
0 Answers
Related