A flutter plugin to draw the coordinates on widget and as well as to find the given point is inside a list of coordinates or not.
DrawOnWidget(
widget: _DrawOnImageWidget(),
correctAnswerCoordinates: selectedPositions,
getXaxis: (xAxis) {
setState(() {
selectedX = xAxis;
});
},
getYaxis: (yAxis) {
setState(() {
selectedY = yAxis;
});
},
showPointer: showPointer,
onTap: () {
setState(() {
showPointer = true;
if (selectedPositions.last.length > 3 &&
selectedPositions.last.first == selectedPositions.last.last) {
selectedPositions.add([]);
}
Offset? nearestValue = Polygon.getNearestPoint(
selectedPositions.last, Offset(selectedX!, selectedY!));
selectedPositions.last.add(Offset(selectedX!, selectedY!));
if (nearestValue != null) {
selectedPositions.last.add(nearestValue);
}
selectedX = null;
selectedY = null;
});
print(selectedPositions);
},
pointsColor: Colors.green,
lineColor: Colors.green,
),
SelectAreaWidget(
correctAnswerCoordinates: correctAnswerCoordinates,
widget: _DrawOnImageWidget(),
isSelectable: isSelectable,
getXaxis: (xAxis) {
setState(() {
selectedPositionX = xAxis;
});
},
showPointer: showPointer,
getYaxis: (yAxis) {
setState(() {
selectedPositionY = yAxis;
});
},
onTap: () {
setState(() {
showPointer = true;
});
},
pointsColor: Colors.red,
lineColor: Colors.green,
),
Polygon.getNearestPoint(points, currentPoints);
Polygon polygon = Polygon(polygonPoints);
isInside = polygon.isPointInside(Offset(xAxis, yAxis));