我在垂直列表中添加了水平列表视图。它不显示任何内容
@override
Widget build(BuildContext context) {
return Scaffold(
body: new ListView.builder(
itemCount: 3,
scrollDirection: Axis.vertical,
itemBuilder: (context, position) {
if (position == 0) {
return Container(
child: Text("First rwo"),
);
} else if (position == 1) {
return Container(
child: Text("second rwo"),
);
} else if (position == 2) {
return Container(
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: 4,
shrinkWrap: true,
itemBuilder: (context, pos) {
return Text("List ");
}));
}
}));
}
当我将height
属性添加到位置2 container
时,它将起作用。
但我要动态高度。
SingleChildScrollView
是另一种选择,但不适用于无限列表。
答案 0 :(得分:1)
在Row
内切换到SingleChildScrollview
:
@override
Widget build(BuildContext context) {
return Scaffold(
body: new ListView.builder(
itemCount: 3,
scrollDirection: Axis.vertical,
itemBuilder: (context, position) {
if (position == 0) {
return Container(
child: Text("First rwo"),
);
} else if (position == 1) {
return Container(
child: Text("second rwo"),
);
} else if (position == 2) {
return SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: [Text("List"), Text("List"), Text("List"), Text("List")],
),
);
}
},
),
);
}