代码:
new GridView(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
crossAxisSpacing: 2.0,
mainAxisSpacing: 2.0,
childAspectRatio: 1.0,
),
children: <Widget>[
// new Text('aaaaaa'),
new Image.network('https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1578312966654&di=09a975b6c05a1447fc6f8aeae463cf41&imgtype=0&src=http%3A%2F%2Fp2.qhimgs4.com%2Ft0128307802c64fd817.jpg',fit: BoxFit.cover),
new Image.network('https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1578312966654&di=09a975b6c05a1447fc6f8aeae463cf41&imgtype=0&src=http%3A%2F%2Fp2.qhimgs4.com%2Ft0128307802c64fd817.jpg',fit: BoxFit.cover),
new Image.network('https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1578312966654&di=09a975b6c05a1447fc6f8aeae463cf41&imgtype=0&src=http%3A%2F%2Fp2.qhimgs4.com%2Ft0128307802c64fd817.jpg',fit: BoxFit.cover),
new Image.network('https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1578312966654&di=09a975b6c05a1447fc6f8aeae463cf41&imgtype=0&src=http%3A%2F%2Fp2.qhimgs4.com%2Ft0128307802c64fd817.jpg',fit: BoxFit.cover),
new Image.network('https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1578312966654&di=09a975b6c05a1447fc6f8aeae463cf41&imgtype=0&src=http%3A%2F%2Fp2.qhimgs4.com%2Ft0128307802c64fd817.jpg',fit: BoxFit.cover),
new Image.network('https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1578312966654&di=09a975b6c05a1447fc6f8aeae463cf41&imgtype=0&src=http%3A%2F%2Fp2.qhimgs4.com%2Ft0128307802c64fd817.jpg',fit: BoxFit.cover)
],
)
总结:
GirdView
老式写法
GirdView.count(
padding:内间距
crossAxisSpacing:列与列之间的间距
crossAxisCount:列数
children:<widget>[
const Text(‘xxxx’)//文本
const Text(‘xxxx’)
const Text(‘xxxx’)
const Text(‘xxxx’)
]
)
新式写法
GirdView(
SliverGridDelegateWithMaxCrossAxisExtent //根据里面内容来扩展
一般使用 SliverGridDelegateWithFixedCrossAxisCount
gridDelegate:SliverGridDelegateWithFixedCrossAxisCount
crossAxisCount:列数
mainAxisSpacing:行间距
crossAxisSpacing:列间距
childAspectRatio:宽高比
)
children : <widget>{
}