Mysql 获取实例字段时出错';颤振中的t最终
我试图将数据从fetch product list页面传递到product detail,但得到的错误是 此类(或此类继承的类)标记为“@immutable”,但其一个或多个实例字段不是最终字段:ProdukGapo.list、ProdukGapo.index 我该怎么修 产品列表代码:Mysql 获取实例字段时出错';颤振中的t最终,mysql,flutter,dart,Mysql,Flutter,Dart,我试图将数据从fetch product list页面传递到product detail,但得到的错误是 此类(或此类继承的类)标记为“@immutable”,但其一个或多个实例字段不是最终字段:ProdukGapo.list、ProdukGapo.index 我该怎么修 产品列表代码: class ItemList extends StatelessWidget { final List list; ItemList({this.list}); @override Widge
class ItemList extends StatelessWidget {
final List list;
ItemList({this.list});
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Container(
height: 200,
child: ListView.builder(
itemCount: list==null ? 0 : list.length,
itemBuilder: (context, i){
return new GestureDetector(
onTap: ()=>MaterialPageRoute(
builder: (BuildContext context)=> ProdukGapo(list: list, index: i,)
) ,
child: new Card(
child: Padding(
padding: const EdgeInsets.all(10.0),
child: ListTile(
title: Text(list[i]["product_name"]),
leading: Icon(Icons.widgets),
subtitle: Text("Price RM : ${list[i]["product_price"]}"),
),
),
),
);
},
),
),
);
}
}
错误零件上的产品详细信息代码:
class ProdukGapo extends StatefulWidget {
List list;
int index;
ProdukGapo({this.index,this.list});
@override
_ProdukGapoState createState() => _ProdukGapoState();
}
我用来调用这个类的类是
class ProdukGapo extends StatefulWidget {
List list;
int index;
ProdukGapo({this.index,this.list});
@override
_ProdukGapoState createState() => _ProdukGapoState();}
在小部件上添加一个常量构造函数
class BottomCardState extends StatefulWidget {
final int _value;
final String title;
const BottomCardState(this._value,this.title)
@override
_BottomCardStateState createState() => _BottomCardStateState();
}
并访问如下参数=>widget.list和widget.index
试试这个你能再解释一下吗?我没有接近解决方案。我已经更新了您需要在有状态类中更改的解决方案。基本上,您需要使变量在核心类中成为final,并将其在state类中的状态更新为“widget.fieldname”。希望这能消除你的疑虑
class ProdukGapo extends StatefulWidget {
final List list;
final int index;
ProdukGapo({Key key, this.list, this.index}) : super(key: key);
@override
_ProdukGapoState createState() => _ProdukGapoState();
}