Is there any way to paint a Widget
at a given position on a Canvas
?
More specifically, I want to paint the child widgets of Marker
's related to a FlutterMap
on a separate Canvas
in front of the actual FlutterMap
widget. Here's an attempt at creating a CustomPainter
that would do that, but I can't figure out how to actually paint the widgets on the canvas. Using the RenderObject
requires a PaintingContext
, which I don't know how to create/retrieve:
class MarkerPainter extends CustomPainter {
MapController mc;
BuildContext context;
List<Marker> markers;
MarkerPainter(this.context, this.mc, this.markers);
@override
void paint(Canvas canvas, Size size) {
if( markers != null && markers.isNotEmpty ){
for(int i=0; i<markers.length; i++){
Marker marker = markers[i];
Offset o = myCalculateOffsetFromLatLng(marker.point, mc, context);
// Won't work, this needs a PaintingContext...
marker.builder(context).createElement().renderObject.paint(context, o);
}
}
}
@override
bool shouldRepaint(MarkerPainter oldDelegate) => oldDelegate.markers != markers;
}