Flutter ReorderableListView 在可滚动父级中无法完美工作

问题描述 投票:0回答:1

在 Flutter 中,当我使用 SingleChildScrollView 将 ReorderableListView 包装在 ListView 或 Column 中时,它会被渲染,但在项目总数的高度超过屏幕高度的情况下,当我将一个项目拖动到屏幕边缘时可重新排序的列表视图不自动滚动。

但是当没有可滚动父项时它工作正常,当我将项目拖动到屏幕边缘时它会自动滚动

这是解释我的问题的简约代码

class _MyHomePageState extends State<MyHomePage> {
  final _items = List.generate(25, (index) => index.toString());

  @override
  Widget build(BuildContext context) {
    // This trailing comma makes auto-formatting nicer for build methods.
    return Scaffold(
      backgroundColor: Colors.grey,
      body: ListView(
        children: [
          Container(
            height: 48 * 25,
            color: Colors.yellow,
            margin: EdgeInsets.only(top: 88),
            child: ReorderableListView.builder(
                physics: ClampingScrollPhysics(),
                shrinkWrap: true,
                itemCount: _items.length,
                itemBuilder: (context, index) {
                  return ListTile(
                    key: ValueKey(_items[index]),
                    title: Text(_items[index]),
                  );
                },
                onReorder: (int oldindex, int newindex) {
                  setState(() {
                    if (newindex > oldindex) {
                      newindex -= 1;
                    }
                    final item = _items.removeAt(oldindex);
                    _items.insert(newindex, item);
                  });
                }),
          ),
        ],
      ),
    );
  }
}

我尝试过使用nestedscrollview,primaryscrollcontroller,但没有得到任何好的结果

flutter flutter-reorderable-listview
1个回答
0
投票

停用嵌套滚动视图的滚动物理:

    physics: NeverScrollableScrollPhysics(),

希望对您有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.