Flutter:打开简单对话框后如何保持手势事件状态

时间:2019-03-09 20:18:58

标签: dart flutter

我有一个图像网格,我想在长按图像时打开一个简单的对话框,当手指不再与屏幕接触时会自动关闭(例如Instagram快速图像预览)。

我在所有图像上附加了LongPress事件,并且工作正常,因此当我长按图像时会打开一个对话框,但是当我举起手指时,即使我附加了onTapUp这样的事件也没有任何反应,onLongPressEndonPointerUp,因为有了新打开的对话框,所有这些事件都丢失了,不再触发。

我试图将指针向上事件添加到打开的对话框中,但是有一个陷阱,我必须再次点击并释放才能使其起作用,因为Flutter无法识别我的手指已经与屏幕接触,并且打开的对话框使Flutter忘记了这一事实。

3 个答案:

答案 0 :(得分:1)

您可以使用OverlayEntryOverlay.of(context).insert(overlayEntry)插入<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <input id="ctl00_plcContent_roles" value="abc,123">堆栈中。

在此叠加层中,您可以在需要时捕获手势并相应地执行操作。由于叠加层始终位于其他任何层之上,因此该对话框不会取消您的长按手势,并且您将能够响应Overlay

您只需要计算已按下的图像或使用longPressEnd提供的Offset和图像的位置即可。

要获取图像的全局位置,可以将GlobalKey's分配给图像,并通过以下方式获取其全局位置:

onTapDown

要获得长按的位置,您将需要存储onTapDown的位置:

final RenderBox renderBox = globalKey.currentContext.findRenderObject() as RenderBox;

final Offset position = renderBox.localToGlobal(Offset.zero);
final Size size = renderBox.size;

现在,您拥有确定长按发生在哪个范围的一切。

答案 1 :(得分:0)

我找到了使之工作的方法。可以使用const input = [["7/7/2020", "raw material", "completed", "yes", "john", "7896785643"], ["7/8/2020", "job material", "partially completed", "no", "ana", "7896785643"], ["7/9/2020", "scrap material", "completed", "yes", "mariam", "7896785643"], ["7/10/2020", "raw material", "completed", "no", "john", "7896785643"], ["7/7/2020", "scrap material", "partiallycompleted", "yes", "andrew", "7896785643"]]; const searchCols = [1,3 ,4]; const searchitems = ["raw","yes","john"]; function filterData3(dataArray,searchitems,searchColumns){ var filtered = dataArray.filter(function(datarow){ return (datarow[searchColumns[0]] === searchitems[0] && datarow[searchColumns[1]] === searchitems[1]); }); return filtered; } const test = filterData3(input, searchitems, searchCols); console.log(test);小部件完成。

在带有Overlay的小部件中,当调用GestureDetector时,请在对话框中创建一个onLongPress对象,并将其插入OverlayEntry

调用Overlay时,请调用onLongPressEnd对象的remove函数。

OverlayEntry

这是Github的要点:

https://gist.github.com/plateaukao/79aa39854dc4eabf1220bdfa9a0334b6

答案 2 :(得分:0)

您可以使用my_fun并在其中放入 "mappings": { "properties": { "name": { "type": "text" }, "id": { "type": "integer" }, "is_active": { "type": "boolean" }, "attributes": { "dynamic": true, "properties": { "subjects": { "type": "integer" }, "occupation": { "type": "integer" } } 。 使用{ "query": { "bool": { "must": [ { "bool": { "should": [ { "terms": { "audience_attributes.occupation": [ 4 ] } } ] } }, { "terms": { "is_active": [ true ] } } ] } } } 更改宽度和高度,然后完成。

AnimatedContainer
相关问题