Flutter StatefulWidget传参注意事项

直接使用父类传递的参数widget.menusData

class ZmXzGridView extends StatefulWidget {
  List menusData=new List();
  ZmXzGridView({Key key,this.menusData}):super(key:key);

  @override
  State createState() {
    // TODO: implement createState
    return ZmXzGridViewState();
  }
}

class ZmXzGridViewState extends State {

  /*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数量
      crossAxisCount: 3,
      //子Widget宽高比例
      childAspectRatio: 1.4,
      //子Widget列表
      children: getWidgetList(widget.menusData.length,widget.menusData),
    );
  }

你可能感兴趣的:(Flutter StatefulWidget传参注意事项)