有没有办法Widget
在 a 的给定位置绘制 a Canvas
?
更具体地说,我想在实际小部件前面单独绘制Marker
与 a 相关的子小部件。这是创建一个可以做到这一点的尝试,但我无法弄清楚如何在画布上实际绘制小部件。使用requires a ,我不知道如何创建/检索:FlutterMap
Canvas
FlutterMap
CustomPainter
RenderObject
PaintingContext
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;
}