I need to create a custom marker for the Google's map. I need to align the left border of the custom marker widget with the pointed location which require me to push the widget half width to the right, so I used FractionalTranslation for that. Of course I still got a full width source widget after the translation. No problem so far.
The problem happened after converted (RenderRepaintBoundary) the widget into marker's icon. The icon lost it's right part, been cut into half.
...
class TheState extends State<TheScreen>{
...
GlobalKey<MarkState> globalkey = GlobalKey<MarkState>();
Set<Marker> marks = Set();
@override
Widget build(BuildContext context){
...
return Scaffold(
...
body : Stack(
children : [
Mark(globalkey),
GoogleMap(
...
markers : marks,
)
]
)
);
}
...
setState((){
marks.clear();
marks.add(Marker(
...
icon : await convert(gk)
));
});
...
Future<BitmapDescriptor> convert(GlobalKey gk) async {
RenderRepaintBoundary boundary = gk.currentContext?.findRenderObject() as RenderRepaintBoundary;
ui.Image image = await boundary.toImage(pixelRatio : 2);
ByteData? byteData = await image.toByteData(format: ui.ImageByteFormat.png);
return BitmapDescriptor.fromBytes(byteData!.buffer.asUint8List());
}
}
...
class MarkState extends State<Mark>{
...
@override
Widget build(BuildContext context) => RepaintBoundary(
child : FractionalTranslation(
translation : Offset(0.5, 0),
child : ...
)
);
}