老师你好,如何实现listview嵌套gridview

来源:10-4 基于GridView实现网格布局【跟着做】

慕娘0065896

2019-08-16

@override
Widget build(BuildContext context) {
return ListView.builder(
itemCount: this.result.length,
itemBuilder: (BuildContext context, int index) {
return Container(
child: Column(
children: [
Row(
children: [
Container(
// height: 100,
// width: 200,
color: Colors.yellow,
child: Text(‘课程名称’),
),
]
),
// Container(
// child: _studentName(),
// )
],
),
);

  },
);

}

Widget _studentName(){
return Row(
children: [
Container(
color: Colors.red,
child: GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
childAspectRatio: 50.0,
mainAxisSpacing: 10.0,
crossAxisSpacing: 10.0
),
itemCount: 5,
itemBuilder: (context, index){
return Container(
height: 80,
width: 80,
decoration: BoxDecoration(
border: Border.all(
color: Colors.black,
width: 3
)
),
child: Text(‘学生姓名’),
);
},
),
)
],
);
}

写回答

1回答

CrazyCodeBoy

2019-08-19

  • 为GridView 添加:

    • shrinkWrap:true;

    • physics: new NeverScrollableScrollPhysics();

body: new ListView(
          shrinkWrap: true,
          padding: EdgeInsets.all(0),
          children: <Widget>[
          	new GridView.count(
      		 padding: EdgeInsets.all(0),
        	physics: new NeverScrollableScrollPhysics(),//增加
        	shrinkWrap: true,//增加
        	crossAxisCount: 3,
        	children:<Widget>[]
          ],
        ),


1
1
慕娘0065896
谢谢大佬
2019-08-20
共1条回复

Flutter从入门到进阶 实战携程网App 一网打尽核心技术

解锁Flutter开发新姿势,,系统掌握Flutter开发核心技术。

4788 学习 · 3270 问题

查看课程