简体   繁体   English

Flutter - ReorderableListView 拖动

[英]Flutter - ReorderableListView on drag

Is it possible to communicate to the children of a ReorderableListView that a drag/reorder attempt has begun?是否可以与 ReorderableListView 的子项沟通拖/重新排序尝试已经开始? I have a ReorderableListView with custom widget children (not ListTile widgets) and I would like to be able to update their view when one of them begins to be dragged.我有一个带有自定义小部件子级(不是 ListTile 小部件)的 ReorderableListView,我希望能够在其中一个开始被拖动时更新他们的视图。 For example, in this case:例如,在这种情况下:

ReorderableListView(
  onReorder: (oldIndex, newIndex) {},
  children: [
    _CustomWidget(0),
    _CustomWidget(1),
    _CustomWidget(2),
  ]
);

I'd like to reduce the opacity of _CustomWidget(0) and _CustomWidget(2) if _CustomWidget(1) has begun to be dragged.如果_CustomWidget(1)已开始被拖动,我想降低_CustomWidget(0)_CustomWidget(2)的不透明度。 I've tried using a GestureDetector to determine if a widget is being dragged but that obviously absorbs the gesture and the ReorderableListView no longer begins the drag.我尝试使用GestureDetector来确定是否正在拖动小部件,但这显然会吸收手势并且ReorderableListView不再开始拖动。

Is there a way to either allow the dragged widget to recognize its being dragged, or have the ReorderableListView somehow communicate to its parent when one of its children are being dragged?有没有办法让被拖动的小部件识别它被拖动,或者当它的一个孩子被拖动时让ReorderableListView以某种方式与其父级通信?

Looks like there is a PR currently awaiting for approval which would help you achieve that !看起来目前有一个 PR 正在等待批准,可以帮助您实现这一目标!
https://github.com/flutter/flutter/pull/96049 https://github.com/flutter/flutter/pull/96049

Once it'll be merged, you'll be able to detect when the reorder has started in order to change the opacity of the other items.合并后,您将能够检测重新排序何时开始,以更改其他项目的不透明度。

If you don't want to wait for the PR to be merged, you can also add the fork with the modification to your project instead of the official ReorderableListview如果不想等 PR 被合并,也可以在你的项目中添加带有修改的 fork,而不是官方的 ReorderableListview

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM