Open jijo0465 opened 4 years ago
Hey, the images will not work. The reason is that they are lazily fetched and they need some time to be read into memory.
There are two fixes for this:
1) Proper fix: is to not use markers_generator_sample because it is not made to support images. It is made as a quicky way of converting simple widgets to markers. A proper fix would probably mean drawing on dart:ui
canvas and converting that to bitmap without using widgets at all.
2) Quick fix: would probably mean using precacheImage and delaying the generation, for example wrap MarkerGenerator.generate with some delay: Future.delayed(Duration(milliseconds: 50), () {
Hey, the images will not work. The reason is that they are lazily fetched and they need some time to be read into memory.
There are two fixes for this:
- Proper fix: is to not use markers_generator_sample because it is not made to support images. It is made as a quicky way of converting simple widgets to markers. A proper fix would probably mean drawing on
dart:ui
canvas and converting that to bitmap without using widgets at all.- Quick fix: would probably mean using precacheImage and delaying the generation, for example wrap MarkerGenerator.generate with some delay:
Future.delayed(Duration(milliseconds: 50), () {
It does not work
I was able to precache my svg images on startup, which leads to a working marker generation.
precachePicture(ExactAssetPicture(SvgPicture.svgStringDecoder, 'assets/images/image.svg'), null);
I did also manage to load images with this. I required both a precachePicture and an await of a delayed future. I also upgraded this to null-safety (I am currently running >=2.17.5 <3.0.0). I will open a PR for it when I apply the concept to your simple example.
Hey, update on this. Although this is a nice workaround, it is really unstable. I spent a lot of hours to apply this, but it is just not worth it. I ended up using "DavinciCapture" (https://pub.dev/packages/davinci) Generating a bitmap is as easy as:
await DavinciCapture.offStage(
widget,
openFilePreview: false,
returnImageUint8List: true,
) as Uint8List;
Then wrap the data with a bitmap descriptor:
BitmapDescriptor.fromBytes(bitmap)
There's no need for context here, no problems with race conditions and no null issues.
The widgets with image providers is not working. I tried giving image as container boxDecoration and Image.asset, both failed.