Home > Software engineering >  Getx not update value
Getx not update value

Time:07-21

I try to learn flutter getX. I writed a controller and put inside a map and a list. But my widget not updating itselfs when maps values changed. i got a one another variables and its name is count. İt is a integer and working succesfully. But i cant say samething for my map. Why its not working. How can i solve it? My controller ;

class Controller extends GetxController {


RxMap<int, ProductModel> purchaseListe= <int, ProductModel>{}.obs; 

RxList<ProductModel> foundedItem = <ProductModel>[].obs;//There are products inside
var count = 0.obs; //the working variable i am talking about


void add(int index, bool isAdded) {
    if (isAdded) {
      foundedItem[index].piece  ;
      print("tıklanan elemean indeks = $index");
      count  ;
      if (foundedItem[index].piece == 1) {
        purchaseListe.addAll({index: foundedItem[index]});
      }
    } else {
      foundedItem[index].piece--;
      print("tıklanan elemean indeks = $index");
      count--;
      if (foundedItem[index].piece == 0) {
        purchaseListe.remove(index);
      }
    }
 
    
    
    update();
  }

}

and my Ui

Container(
            height: 25,
            width: 25.0,
            child: Obx(
              () {
              
                return Text(
                  widgetController.foundedItem[widget.itemIndex].piece
                      .toString(),
             
                );
              },
            ),
          ),

My model

class ProductModel {
  String productCode;
  String productName;
  var productPrice;
  var productSalePrice;
  var productScore;
  String productImageUrl;
  int piece;

  ProductModel({
    required this.productCode,
    required this.productName,
    this.productPrice,
    this.productSalePrice,
    this.productScore,
    required this.productImageUrl,
    required this.piece,
  });
}

CodePudding user response:

Please update map like this.

purchaseListe.value = {index: "updated item"};
  • Related