Column 内的 ListView 导致 'Vertical viewport was given unbounded height'
ListView inside Column causes 'Vertical viewport was given unbounded height'
我是 Flutter 的新手,在布局方面遇到了麻烦。
我想要这样的东西:
粘性 header 和下面的滚动视图。
我想过将 Column 小部件与两个 children 一起使用 - 第一个是 header,第二个是 ListView。
这是我的代码
Widget build(BuildContext context) {
return Material(
elevation: 8.0,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(16.0),
child: Text(
title,
style:
Theme.of(context).textTheme.subhead.copyWith(fontSize: 18.0),
textAlign: TextAlign.left,
),
),
Divider(height: 4.0),
ListView.builder(itemBuilder: (context, i) {
return ListTile(
title: Text("Title $i"),
subtitle: Text("Subtitle $i"),
);
}),
],
),
);
}
我收到以下错误。
I/flutter ( 5725): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter ( 5725): The following assertion was thrown during performResize():
I/flutter ( 5725): Vertical viewport was given unbounded height.
I/flutter ( 5725): Viewports expand in the scrolling direction to fill their container.In this case, a vertical
I/flutter ( 5725): viewport was given an unlimited amount of vertical space in which to expand. This situation
I/flutter ( 5725): typically happens when a scrollable widget is nested inside another scrollable widget.
I/flutter ( 5725): If this widget is always nested in a scrollable widget there is no need to use a viewport because
I/flutter ( 5725): there will always be enough vertical space for the children. In this case, consider using a Column
I/flutter ( 5725): instead. Otherwise, consider using the "shrinkWrap" property (or a ShrinkWrappingViewport) to size
I/flutter ( 5725): the height of the viewport to the sum of the heights of its children.
我在消息中添加了make shrinkWrap of ListView true,但这也没有用。
此布局的 parent 是一个包含各种此类 layout-pages 的堆栈,所有此布局页面都在后台,期望一个用户已选择。
我做错了什么?
尝试用 Flexible
或 Expanded
小部件包装您的 ListView.builder
:
Flexible(
child: ListView.builder(
itemBuilder: (context, i) {
return ListTile(
title: Text("Title $i"),
subtitle: Text("Subtitle $i"),
);
},
),
),
我是 Flutter 的新手,在布局方面遇到了麻烦。
我想要这样的东西:
粘性 header 和下面的滚动视图。 我想过将 Column 小部件与两个 children 一起使用 - 第一个是 header,第二个是 ListView。
这是我的代码
Widget build(BuildContext context) {
return Material(
elevation: 8.0,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(16.0),
child: Text(
title,
style:
Theme.of(context).textTheme.subhead.copyWith(fontSize: 18.0),
textAlign: TextAlign.left,
),
),
Divider(height: 4.0),
ListView.builder(itemBuilder: (context, i) {
return ListTile(
title: Text("Title $i"),
subtitle: Text("Subtitle $i"),
);
}),
],
),
);
}
我收到以下错误。
I/flutter ( 5725): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter ( 5725): The following assertion was thrown during performResize():
I/flutter ( 5725): Vertical viewport was given unbounded height.
I/flutter ( 5725): Viewports expand in the scrolling direction to fill their container.In this case, a vertical
I/flutter ( 5725): viewport was given an unlimited amount of vertical space in which to expand. This situation
I/flutter ( 5725): typically happens when a scrollable widget is nested inside another scrollable widget.
I/flutter ( 5725): If this widget is always nested in a scrollable widget there is no need to use a viewport because
I/flutter ( 5725): there will always be enough vertical space for the children. In this case, consider using a Column
I/flutter ( 5725): instead. Otherwise, consider using the "shrinkWrap" property (or a ShrinkWrappingViewport) to size
I/flutter ( 5725): the height of the viewport to the sum of the heights of its children.
我在消息中添加了make shrinkWrap of ListView true,但这也没有用。
此布局的 parent 是一个包含各种此类 layout-pages 的堆栈,所有此布局页面都在后台,期望一个用户已选择。
我做错了什么?
尝试用 Flexible
或 Expanded
小部件包装您的 ListView.builder
:
Flexible(
child: ListView.builder(
itemBuilder: (context, i) {
return ListTile(
title: Text("Title $i"),
subtitle: Text("Subtitle $i"),
);
},
),
),