老师你好,如何实现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回答
-
为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>[] ], ),
112019-08-20
相似问题