“不正确的GestureDetector参数”

huangapple go评论62阅读模式
英文:

Incorrect GestureDetector arguments

问题

以下是您要翻译的内容:

"我有一个 GestureDetector,如果我缩放它,它会增加或减少纬度和经度的值,接下来如果我移动它,它会再次对纬度和经度进行相同的操作。

请注意,这些值是在 flutter_map 上的图像叠加的值。

如果我使用 onScaleUpdateonPanUpdate 中的任何一个,都可以正常工作,但如果我同时使用两者,我会收到以下错误消息:

构建 LayoutBuilder 时抛出以下断言:
不正确的 GestureDetector 参数。
同时具有平移手势识别器和缩放手势识别器是多余的;缩放是平移的超集。
只需使用缩放手势识别器。

我需要特定的纬度和经度值,还有其他值将使用 scaleoffset,但这不是我想要的,因为最终我需要将它们转换为纬度和经度。

简而言之,如何在我的手势检测器中同时使用缩放和平移?

这是您的代码:

Positioned(
    top: 250,
    right: 10,
    child: GestureDetector(
        onScaleUpdate: (details) {
            double scaleFactor = details.scale;
            if (scaleFactor > 1) {
                topL[chosenPlate] !.latitude += tolerance;
                botL[chosenPlate] !.latitude -= tolerance;
                botR[chosenPlate] !.latitude -= tolerance;
                topL[chosenPlate] !.longitude -= tolerance;
                botL[chosenPlate] !.longitude -= tolerance;
                botR[chosenPlate] !.longitude += tolerance;
            } else if (scaleFactor < 1) {
                topL[chosenPlate] !.latitude -= tolerance;
                topL[chosenPlate] !.longitude -= tolerance;
                botL[chosenPlate] !.latitude += tolerance;
                botL[chosenPlate] !.longitude -= tolerance;
                botR[chosenPlate] !.latitude += tolerance;
                botR[chosenPlate] !.longitude += tolerance;
            }
        },
        onPanUpdate: (details) {
            if (details.delta.dx < 0) {
                setState(() {
                    topL[chosenPlate] !.longitude -= tolerance;
                    botL[chosenPlate] !.longitude -= tolerance;
                    botR[chosenPlate] !.longitude -= tolerance;
                });
            } else if (details.delta.dx > 0) {
                setState(() {
                    topL[chosenPlate] !.longitude += tolerance;
                    botL[chosenPlate] !.longitude += tolerance;
                    botR[chosenPlate] !.longitude += tolerance;
                });
            } else if (details.delta.dy < 0) {
                setState(() {
                    topL[chosenPlate] !.latitude += tolerance;
                    botL[chosenPlate] !.latitude += tolerance;
                    botR[chosenPlate] !.latitude += tolerance;
                });
            } else if (details.delta.dy > 0) {
                setState(() {
                    topL[chosenPlate] !.latitude -= tolerance;
                    botL[chosenPlate] !.latitude -= tolerance;
                    botR[chosenPlate] !.latitude -= tolerance;
                });
            }
        },
        child: Container(
            height: 20. h,
            width: 30. w,
            color: Color.fromARGB(255, 233, 176, 176),
        ),
    ),
),

希望这有所帮助。

英文:

so i have a GestureDetector where if i scale it will increase or decrease the values ,The values are latitude and longitude, Next if i pan it will again do the same for latitude and longitude,

Please note these values are the values of image overlay on flutter_map

if I use either onScaleUpdate or onPanUpdate it works fine, but if i use both i get the error

The following assertion was thrown building LayoutBuilder:
Incorrect GestureDetector arguments.

Having both a pan gesture recognizer and a scale gesture recognizer is redundant; scale is a superset of pan.

Just use the scale gesture recognizer.

I need the specific latitude and longitude values , there are other values that will use scale or offset but this is not what i want as eventually i will need to convert those to latitude and longitude.

in short, how can use scale and pan at the same time in my gesture detector

this is the code

Positioned(
    top: 250,
    right: 10,
    child: GestureDetector(
        onScaleUpdate: (details) {
            double scaleFactor = details.scale;
            if (scaleFactor > 1) {
                topL[chosenPlate] !.latitude += tolerance;
                botL[chosenPlate] !.latitude -= tolerance;
                botR[chosenPlate] !.latitude -= tolerance;
                topL[chosenPlate] !.longitude -= tolerance;
                botL[chosenPlate] !.longitude -= tolerance;
                botR[chosenPlate] !.longitude += tolerance;
            } else if (scaleFactor < 1) {
                topL[chosenPlate] !.latitude -= tolerance;
                topL[chosenPlate] !.longitude -= tolerance;
                botL[chosenPlate] !.latitude += tolerance;
                botL[chosenPlate] !.longitude -= tolerance;
                botR[chosenPlate] !.latitude += tolerance;
                botR[chosenPlate] !.longitude += tolerance;
            }
        },
        onPanUpdate: (details) {
            if (details.delta.dx < 0) {
                setState(() {
                    topL[chosenPlate] !.longitude -= tolerance;
                    botL[chosenPlate] !.longitude -= tolerance;
                    botR[chosenPlate] !.longitude -= tolerance;
                });
            } else if (details.delta.dx > 0) {
                setState(() {
                    topL[chosenPlate] !.longitude += tolerance;
                    botL[chosenPlate] !.longitude += tolerance;
                    botR[chosenPlate] !.longitude += tolerance;
                });
            } else if (details.delta.dy < 0) {
                setState(() {
                    topL[chosenPlate] !.latitude += tolerance;
                    botL[chosenPlate] !.latitude += tolerance;
                    botR[chosenPlate] !.latitude += tolerance;
                });
            } else if (details.delta.dy > 0) {
                setState(() {
                    topL[chosenPlate] !.latitude -= tolerance;
                    botL[chosenPlate] !.latitude -= tolerance;
                    botR[chosenPlate] !.latitude -= tolerance;
                });
            }
        },
        child: Container(
            height: 20. h,
            width: 30. w,
            color: Color.fromARGB(255, 233, 176, 176),
        ),
    ),
),

答案1

得分: 1

以下是翻译好的部分:

根据消息所说,您需要使用 onScaleUpdate 来处理平移操作。我认为在 onScaleUpdate 中可以使用 details.focalPointDelta 替代 onPanUpdate 中的 details.delta,代码如下:

onScaleUpdate: (details) {
    double scaleFactor = details.scale;
    if (scaleFactor > 1) {
        topL[chosenPlate]!.latitude += tolerance;
        botL[chosenPlate]!.latitude -= tolerance;
        botR[chosenPlate]!.latitude -= tolerance;
        topL[chosenPlate]!.longitude -= tolerance;
        botL[chosenPlate]!.longitude -= tolerance;
        botR[chosenPlate]!.longitude += tolerance;
    } else if (scaleFactor < 1) {
        topL[chosenPlate]!.latitude -= tolerance;
        topL[chosenPlate]!.longitude -= tolerance;
        botL[chosenPlate]!.latitude += tolerance;
        botL[chosenPlate]!.longitude -= tolerance;
        botR[chosenPlate]!.latitude += tolerance;
        botR[chosenPlate]!.longitude += tolerance;
    }

    if (details.focalPointDelta.dx < 0) {
        setState(() {
            topL[chosenPlate]!.longitude -= tolerance;
            botL[chosenPlate]!.longitude -= tolerance;
            botR[chosenPlate]!.longitude -= tolerance;
        });
    } else if (details.focalPointDelta.dx > 0) {
        setState(() {
            topL[chosenPlate]!.longitude += tolerance;
            botL[chosenPlate]!.longitude += tolerance;
            botR[chosenPlate]!.longitude += tolerance;
        });
    } else if (details.focalPointDelta.dy < 0) {
        setState(() {
            topL[chosenPlate]!.latitude += tolerance;
            botL[chosenPlate]!.latitude += tolerance;
            botR[chosenPlate]!.latitude += tolerance;
        });
    } else if (details.focalPointDelta.dy > 0) {
        setState(() {
            topL[chosenPlate]!.latitude -= tolerance;
            botL[chosenPlate]!.latitude -= tolerance;
            botR[chosenPlate]!.latitude -= tolerance;
        });
    }
},
英文:

As the message says, you need to use the onScaleUpdate to handle the panning as well. I believe details.focalPointDelta can be used in the onScaleUpdate instead of the details.delta in onPanUpdate, so it will be:

    onScaleUpdate: (details) {
        double scaleFactor = details.scale;
        if (scaleFactor &gt; 1) {
            topL[chosenPlate] !.latitude += tolerance;
            botL[chosenPlate] !.latitude -= tolerance;
            botR[chosenPlate] !.latitude -= tolerance;
            topL[chosenPlate] !.longitude -= tolerance;
            botL[chosenPlate] !.longitude -= tolerance;
            botR[chosenPlate] !.longitude += tolerance;
        } else if (scaleFactor &lt; 1) {
            topL[chosenPlate] !.latitude -= tolerance;
            topL[chosenPlate] !.longitude -= tolerance;
            botL[chosenPlate] !.latitude += tolerance;
            botL[chosenPlate] !.longitude -= tolerance;
            botR[chosenPlate] !.latitude += tolerance;
            botR[chosenPlate] !.longitude += tolerance;
        }

        if (details.focalPointDelta.dx &lt; 0) {
            setState(() {
                topL[chosenPlate] !.longitude -= tolerance;
                botL[chosenPlate] !.longitude -= tolerance;
                botR[chosenPlate] !.longitude -= tolerance;
            });
        } else if (details.focalPointDelta.dx &gt; 0) {
            setState(() {
                topL[chosenPlate] !.longitude += tolerance;
                botL[chosenPlate] !.longitude += tolerance;
                botR[chosenPlate] !.longitude += tolerance;
            });
        } else if (details.focalPointDelta.dy &lt; 0) {
            setState(() {
                topL[chosenPlate] !.latitude += tolerance;
                botL[chosenPlate] !.latitude += tolerance;
                botR[chosenPlate] !.latitude += tolerance;
            });
        } else if (details.focalPointDelta.dy &gt; 0) {
            setState(() {
                topL[chosenPlate] !.latitude -= tolerance;
                botL[chosenPlate] !.latitude -= tolerance;
                botR[chosenPlate] !.latitude -= tolerance;
            });
        }
    },

huangapple
  • 本文由 发表于 2023年4月17日 15:05:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76032474.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定