【问题标题】:Flutter - Reorderable List with a Listview nested inside expansiontileFlutter - 可重新排序的列表,Listview 嵌套在 expandtile 内
【发布时间】:2020-08-16 01:57:36
【问题描述】:

我正在尝试使用可重新排序的列表视图构建一个示例,该列表视图将扩展图块作为其子项。 展开图块后,它将向用户显示一个列表视图,如下所示 Expanded tile with listview nested inside

当所有扩展图块都折叠时,我可以通过长按和移动来重新排列图块。但是如果其中一个瓦片被展开,并且用户尝试重新排列瓦片,颤振将抛出以下错误并且展开的瓦片将无法折叠,直到热重新加载

ScrollController attached to multiple scroll views.
'package:flutter/src/widgets/scroll_controller.dart':
Failed assertion: line 111 pos 12: '_positions.length == 1'

Not Collapsible listview

我应该如何修复它?该问题似乎源于将滚动控制器嵌套在另一个滚动控制器中。有没有办法在长按时强制所有膨胀瓦片塌陷? 提前致谢

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()),
      ),
    ),
  );

【问题讨论】:

    标签: android listview flutter dart reorderable-list


    【解决方案1】:

    我能够通过 Flutter 1.17 的新版本解决上述问题,该版本引入了以下内容

    Flutter 1.17.0 的更改日志

    49148 ReorderableListView 中暴露了可选的 scrollController 属性

    通过在我的 reorderablelistview 中添加滚动控制器,当列表视图嵌套在 reorderablelistview 小部件中时,我不再遇到上面的多个滚动视图错误

     ReorderableListView(
              scrollController: ScrollController(initialScrollOffset: 50),
    

    【讨论】:

      猜你喜欢
      • 2019-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-07
      • 2021-05-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多