相关:Flutter 之列表和头部 (ListView + Header
ListView嵌套GridView解决方案:(ListView嵌套ListView同理)
GridView中添加:
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
ListView中添加:
shrinkWrap: true,
示例代码如下:
// 更多
Widget gameListWidget = Container(
margin: EdgeInsets.symmetric(horizontal: 20.0),
child: GridView.builder(
shrinkWrap: true, // 添加
physics: NeverScrollableScrollPhysics(),// 添加
itemCount: _gameModelList.length ?? 0,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 4, // 横轴元素个数
mainAxisSpacing: 10.0, // 纵轴间距
crossAxisSpacing: 10.0, // 横轴间距
childAspectRatio: 1.0, // 子组件宽高长度比例
),
itemBuilder: (BuildContext context, int index) {
return new GestureDetector(
onTap: () {
},
child: null,
);
},
),
);
return SafeArea(
child: new ListView(
shrinkWrap: true,// 添加
padding: EdgeInsets.all(0),
children: <Widget>[
gameListWidget,
],
),
);
网友评论