markers_generator_sample icon indicating copy to clipboard operation
markers_generator_sample copied to clipboard

Widget with images does not work

Open jijo0465 opened this issue 5 years ago • 5 comments

The widgets with image providers is not working. I tried giving image as container boxDecoration and Image.asset, both failed.

jijo0465 avatar Apr 11 '20 19:04 jijo0465

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), () {

itsJoKr avatar Apr 11 '20 19:04 itsJoKr

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), () {

It does not work

CongBaDo avatar Oct 06 '20 15:10 CongBaDo

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);

C4s4r avatar Jun 12 '21 13:06 C4s4r

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.

memoriasIT avatar Oct 20 '22 09:10 memoriasIT

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.

memoriasIT avatar Feb 03 '23 08:02 memoriasIT