[英]Flutter Items inside ExpansionTile inside ListView are not scrollable
[英]Flutter - Reorderable List with a Listview nested inside expansiontile
我正在尝试使用可重新排序的列表视图构建一个示例,该列表视图具有扩展图块作为其子项。 展开图块后,它将向用户显示一个列表视图,如下所示 展开图块,其中嵌套了列表视图
当所有扩展图块都折叠时,我可以通过长按和移动来重新排列图块。 但是如果其中一个瓦片被展开,并且用户尝试重新排列瓦片,flutter 将抛出以下错误并且展开的瓦片将无法折叠直到热重新加载
ScrollController attached to multiple scroll views.
'package:flutter/src/widgets/scroll_controller.dart':
Failed assertion: line 111 pos 12: '_positions.length == 1'
我应该如何修复它? 该问题似乎源于将滚动 controller 嵌套在另一个滚动 controller 中。 有没有办法在长按时强制所有扩展瓦片塌陷? 提前致谢
List<int> a = [1, 2, 3];
class _BlankPageState extends State<BlankPage> {
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: Padding(
padding: EdgeInsets.all(10),
child: ReorderableListView(
onReorder: (oldIndex, newIndex) {
print('now');
setState(
() {
if (newIndex > oldIndex) {
newIndex -= 1;
}
final int item = a.removeAt(oldIndex);
a.insert(newIndex, item);
},
);
},
children: a.map((index) {
return ExpansionTile(
backgroundColor: Colors.grey,
key: Key('$index'),
title: Text('Tile' + '${index.toString()}'),
children: <Widget>[
Container(
height: 100,
child: ListView(children: <Widget>[
Text('This is a test' + '$index'),
Text('This is a test' + '$index'),
]),
)
],
);
}).toList()),
),
),
);
我能够通过 Flutter 1.17 的新版本解决上述问题,该版本引入了以下内容
Flutter 1.17.0 的更改日志
49148 在 ReorderableListView 中公开了可选的 scrollController 属性
通过在我的 reorderablelistview 中添加滚动 controller,当列表视图嵌套在 reorderablelistview 小部件中时,我不再遇到上面的多个滚动视图错误
ReorderableListView(
scrollController: ScrollController(initialScrollOffset: 50),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.