undoLastAction method
Undoes the last added point and removes the corresponding circle.
Implementation
@override
Future<void> undoLastAction() async {
if (_linePoints.isEmpty || _controller.isLoading) return;
_controller._setLoading(true);
_linePoints.removeLast();
_controller.notifyListeners();
try {
// Remove the last circle annotation
if (_circleAnnotations.isNotEmpty) {
final lastCircle = _circleAnnotations.removeLast();
await _circleAnnotationManager!.delete(lastCircle);
}
if (_linePoints.length >= 2) {
// Update the line with the remaining points
_currentLine?.geometry = LineString.fromPoints(points: _linePoints);
await _polylineAnnotationManager!.update(_currentLine!);
} else {
// If less than 2 points, remove the line completely
if (_currentLine != null) {
await _polylineAnnotationManager!.delete(_currentLine!);
_currentLine = null;
}
}
_controller.notifyListeners();
} catch (e) {
print('Error undoing last line point: $e');
} finally {
_controller._setLoading(false);
}
}