直接使用父類傳遞的參數(shù)widget.menusData
class ZmXzGridView extends StatefulWidget {
List menusData=new List();
ZmXzGridView({Key key,this.menusData}):super(key:key);
@override
State<StatefulWidget> createState() {
// TODO: implement createState
return ZmXzGridViewState();
}
}
class ZmXzGridViewState extends State<ZmXzGridView> {
/*List menusData;
ZmXzGridViewState(this.menusData);*/
String imgUrl;
int curIndex = 0;
void _updateTuan(Menu menu, int index) {
setState(() {
if (curIndex != index) {
curIndex = index;
menu.select = true;
}
});
}
@override
Widget build(BuildContext context) {
return GridView.count(
padding: EdgeInsets.zero,
shrinkWrap: true,
//水平子Widget之間間距
crossAxisSpacing: 10.0,
//垂直子Widget之間間距
mainAxisSpacing: 10.0,
//一行的Widget數(shù)量
crossAxisCount: 3,
//子Widget寬高比例
childAspectRatio: 1.4,
//子Widget列表
children: getWidgetList(widget.menusData.length,widget.menusData),
);
}