ExpansionTile 内的 ListView 不起作用
ListView inside ExpansionTile doesn't work
listview 在 ExpansionTile 中不工作
我试图在 ExpansionTile 中显示一个 listview.builder,但它抛出了一些异常
Card(
child: ExpansionTile(
leading: Icon(
Icons.stars,
color: Colors.pinkAccent,
),
title: Text('Reviews',
style: Theme.of(context).textTheme.title,
),
children: [
ListView.builder(
itemCount: 5,
itemBuilder: (_, i) {
return (Text('item $i'));
})
],
),
),
我想达到这样的效果https://imgur.com/a/0lubABC
══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter ( 8182): The following assertion was thrown during performResize():
I/flutter ( 8182): Vertical viewport was given unbounded height.
I/flutter ( 8182): Viewports expand in the scrolling direction to fill their container.In this case, a vertical
I/flutter ( 8182): viewport was given an unlimited amount of vertical space in which to expand. This situation
I/flutter ( 8182): typically happens when a scrollable widget is nested inside another scrollable widget.
I/flutter ( 8182): If this widget is always nested in a scrollable widget there is no need to use a viewport because
I/flutter ( 8182): there will always be enough vertical space for the children. In this case, consider using a Column
I/flutter ( 8182): instead. Otherwise, consider using the "shrinkWrap" property (or a ShrinkWrappingViewport) to size
I/flutter ( 8182): the height of the viewport to the sum of the heights of its children.
I/flutter ( 8182):
您的 ListView
的垂直尺寸没有限制,因此无法呈现。将 ListView
的 shrinkWrap
属性 设置为 true
来解决这个问题。
将 shrinkwrap 和控制器都添加到 ListView.builder
final ScrollController _scrollController = ScrollController();
ListView.builder(
controller: _scrollController,
shrinkWrap: true,
...
上述解决方案的 None 没有按预期工作。所以我已经解决了这个问题。您需要在 Listview.builder() 内 ExpansionTile children:
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
完整代码:
ExpansionTile(
onExpansionChanged: (e){
//Your code
},
title: Text("You title text"),
children: [
ListView.builder(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
scrollDirection: Axis.vertical,
itemCount: items.length,
itemBuilder: (BuildContext context, int index){
return Text(items[index]);
}
)
],
),
要在 ListView
参数中使用 shrinkWrap: true,
。
listview 在 ExpansionTile 中不工作
我试图在 ExpansionTile 中显示一个 listview.builder,但它抛出了一些异常
Card(
child: ExpansionTile(
leading: Icon(
Icons.stars,
color: Colors.pinkAccent,
),
title: Text('Reviews',
style: Theme.of(context).textTheme.title,
),
children: [
ListView.builder(
itemCount: 5,
itemBuilder: (_, i) {
return (Text('item $i'));
})
],
),
),
我想达到这样的效果https://imgur.com/a/0lubABC
══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter ( 8182): The following assertion was thrown during performResize():
I/flutter ( 8182): Vertical viewport was given unbounded height.
I/flutter ( 8182): Viewports expand in the scrolling direction to fill their container.In this case, a vertical
I/flutter ( 8182): viewport was given an unlimited amount of vertical space in which to expand. This situation
I/flutter ( 8182): typically happens when a scrollable widget is nested inside another scrollable widget.
I/flutter ( 8182): If this widget is always nested in a scrollable widget there is no need to use a viewport because
I/flutter ( 8182): there will always be enough vertical space for the children. In this case, consider using a Column
I/flutter ( 8182): instead. Otherwise, consider using the "shrinkWrap" property (or a ShrinkWrappingViewport) to size
I/flutter ( 8182): the height of the viewport to the sum of the heights of its children.
I/flutter ( 8182):
您的 ListView
的垂直尺寸没有限制,因此无法呈现。将 ListView
的 shrinkWrap
属性 设置为 true
来解决这个问题。
将 shrinkwrap 和控制器都添加到 ListView.builder
final ScrollController _scrollController = ScrollController();
ListView.builder(
controller: _scrollController,
shrinkWrap: true,
...
None 没有按预期工作。所以我已经解决了这个问题。您需要在 Listview.builder() 内 ExpansionTile children:
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
完整代码:
ExpansionTile(
onExpansionChanged: (e){
//Your code
},
title: Text("You title text"),
children: [
ListView.builder(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
scrollDirection: Axis.vertical,
itemCount: items.length,
itemBuilder: (BuildContext context, int index){
return Text(items[index]);
}
)
],
),
要在 ListView
参数中使用 shrinkWrap: true,
。