Reputation: 721
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),
),
),
),
Upvotes: 1
Views: 400
Reputation: 23277
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 > 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;
});
}
},
Upvotes: 1