Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 颤振提供程序模式不影响列表内容更改小部件上的UI更改_Flutter_Dart_Flutter Layout - Fatal编程技术网

Flutter 颤振提供程序模式不影响列表内容更改小部件上的UI更改

Flutter 颤振提供程序模式不影响列表内容更改小部件上的UI更改,flutter,dart,flutter-layout,Flutter,Dart,Flutter Layout,一旦我直接更改值,UI就会更新, 但当我更改列表中某个项目的值时,情况并非如此 以前会有人遇到过这种挑战吗? 请解释为什么会发生这种情况。 有哪些替代方案可用 class Item { int itemQty; final double itemPrice; final double itemDiscount; Item({ this.itemDiscount, this.itemQty, thi

一旦我直接更改值,UI就会更新, 但当我更改列表中某个项目的值时,情况并非如此 以前会有人遇到过这种挑战吗? 请解释为什么会发生这种情况。 有哪些替代方案可用

 class Item {
      int itemQty;
      final double itemPrice;
      final double itemDiscount;

      Item({
        this.itemDiscount,
        this.itemQty,
        this.itemPrice,
      });

      Map<String, Object> toJson() {
        return {
          'itemPrice': itemPrice,
          'itemQun': itemQty,
          'itemDiscount': itemDiscount,
        };
      }    
        class Home extends StatelessWidget {    
          @override
          Widget build(BuildContext context) {    
          return Scaffold(
              body:Container(
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: <Widget>[
        IconButton(
                                        icon: Icon(Icons.remove_circle,
                                            color: Colors.amber.shade500),
                                        onPressed: () {
                                          if (model.quantity >
                                              0) {
                                            model.quantity--;
                                          }
                                        },
                                      ),

                                      new IconButton(
                                        icon: Icon(Icons.remove_circle,
                                            color: Colors.amber.shade500),
                                        onPressed: () {
                                          if (itemList[ind].itemQty >
                                              0) {
                                            Provider.of<MakanikaModel>(
                                              context,
                                            ).requestItems[ind].itemQty--;
                                          }
                                        },
                                      )
                  ],
                ),            
              ),  
            );
          }
        }
类项目{
int itemQty;
最终双倍价格;
最终双倍折扣;
项目({
这是折扣,
这个.itemQty,
这个价格,
});
映射到JSON(){
返回{
“itemPrice”:itemPrice,
“itemQun”:itemQty,
“项目折扣”:项目折扣,
};
}    
类Home扩展了无状态控件{
@凌驾
小部件生成(BuildContext上下文){
返回脚手架(
主体:容器(
子:列(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
图标按钮(
图标:图标(Icons.remove_圈,
颜色:颜色。琥珀色。阴影500),
已按下:(){
如果(型号数量>
0) {
型号.数量--;
}
},
),
新图标按钮(
图标:图标(Icons.remove_圈,
颜色:颜色。琥珀色。阴影500),
已按下:(){
如果(项目列表[ind]。项目数量>
0) {
提供者(
上下文
).requestItems[ind].itemQty--;
}
},
)
],
),            
),  
);
}
}

你需要一个setState。你能展示一下MakanikaModel类的实现吗?
用ChangeNotifier{List _requestItems=List();int _quantity=0;set quantity(newValue){{u quantity=newValue;notifyListeners();}set requestItems(newValue){{u requestItems=newValue;notifyListeners();}//getters List get requestItems=>\u requestItems;int get quantity=>\u quantity;}
@RémiRousselet am using provider set state是带provider的内置状态。