首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >用拖拽法在SliverList中重新排序项目

用拖拽法在SliverList中重新排序项目
EN

Stack Overflow用户
提问于 2018-12-30 18:43:10
回答 3查看 5.6K关注 0票数 4

我正在使用带有SliverChildBuilderDelegateSliverList来动态生成列表项。现在,我正在尝试允许用户通过拖放在一行中的每个项目上的句柄图标上重新排序列表项目。

我尝试过不同的东西(比如可拖放的Widget),但到目前为止我还没有找到解决方案。是否有人已经使用过SliverList Widget的拖放重新排序,并能给我一个提示?

使用ReorderableListView Widget是不可能的,导致将ListView与SliverList混合。我想使用SliverAppBar来允许渐变滚动效果,如您在这里看到的:https://medium.com/flutter-io/slivers-demystified-6ff68ab0296f

这里是我的SliverList:的结构

代码语言:javascript
运行
复制
return Scaffold(
  body: RefreshIndicator(
    ...
    child: CustomScrollView(
      ...
      slivers: <Widget>[
        SliverAppBar(...),
        SliverList(
          delegate: SliverChildBuilderDelegate(...),
        )
        ...

提前谢谢,迈克尔

EN

回答 3

Stack Overflow用户

发布于 2019-03-05 07:12:32

看看这个酒吧里的再订购品包。它最近增加了对SliverList的支持。

截图:ReorderableSliverList

该示例有条条列表和应用程序栏,并显示了您正在寻找的内容。只需将代码中的SliverList和SliverChildBuilderDelegate替换为包中的计数器部件即可。

代码语言:javascript
运行
复制
class _SliverExampleState extends State<SliverExample> {
  List<Widget> _rows;

  @override
  void initState() {
    super.initState();
    _rows = List<Widget>.generate(50,
        (int index) => Text('This is sliver child $index', textScaleFactor: 2)
    );
  }

  @override
  Widget build(BuildContext context) {
    void _onReorder(int oldIndex, int newIndex) {
      setState(() {
        Widget row = _rows.removeAt(oldIndex);
        _rows.insert(newIndex, row);
      });
    }
    ScrollController _scrollController = PrimaryScrollController.of(context) ?? ScrollController();

    return CustomScrollView(
      // a ScrollController must be included in CustomScrollView, otherwise
      // ReorderableSliverList wouldn't work
      controller: _scrollController,
      slivers: <Widget>[
        SliverAppBar(
          expandedHeight: 210.0,
          flexibleSpace: FlexibleSpaceBar(
            title: Text('ReorderableSliverList'),
            background: Image.network(
              'https://upload.wikimedia.org/wikipedia/commons/thumb/6/68/Yushan'
                '_main_east_peak%2BHuang_Chung_Yu%E9%BB%83%E4%B8%AD%E4%BD%91%2B'
                '9030.png/640px-Yushan_main_east_peak%2BHuang_Chung_Yu%E9%BB%83'
                '%E4%B8%AD%E4%BD%91%2B9030.png'),
          ),
        ),
        ReorderableSliverList(
          delegate: ReorderableSliverChildListDelegate(_rows),
          // or use ReorderableSliverChildBuilderDelegate if needed
//          delegate: ReorderableSliverChildBuilderDelegate(
//            (BuildContext context, int index) => _rows[index],
//            childCount: _rows.length
//          ),
          onReorder: _onReorder,
        )
      ],
    );
  }
}
票数 3
EN

Stack Overflow用户

发布于 2019-01-10 03:27:23

你可以去看看列表。我还没有试过它,目前正处于滚动自己的过程中,但是它看起来很不错,例句使用了一个带有SliverList的CustomScrollView。

票数 0
EN

Stack Overflow用户

发布于 2022-09-20 10:20:32

现在可以从正式的颤振小部件库中使用SliverReorderableList

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53980410

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档