使用前:
使用后:
class HomeContext extends StatelessWidget {
Widget _getData(context,index) {
return
Padding(
padding: EdgeInsets.fromLTRB(10, 10, 0, 0),
child:Image.network(listData[index]['imgUrl'],//listData为dart.dart里面的数据
fit: BoxFit.cover,),
);
}
@override
Widget build(BuildContext context) {
// TODO: implement build
return Padding(
padding: EdgeInsets.fromLTRB(0, 0, 10, 0),
child: GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,//每一行Widget的数量
childAspectRatio: 0.8),
itemCount: listData.length,
itemBuilder: this._getData
)
);
}
}