Baseflow / octo_image

A multifunctional Flutter image widget
https://baseflow.com/
MIT License
156 stars 23 forks source link

extend OctoImage-->imageBuilder to also include the imageprovider #13

Open rooscarljohan opened 3 years ago

rooscarljohan commented 3 years ago

Great package!

Sometimes it is also valuable to obtain the imageprovider in the imageBuilder constructor.

Currently it looks like this: typedef OctoImageBuilder = Widget Function(BuildContext context, Widget child);

Hence I'd like it changed to typedef OctoImageBuilder = Widget Function(BuildContext context, Widget child, Imageprovider image);

Had a look at CachedNetworkImage, and did a workaround:

  ImageProvider imageProvider =...

   return OctoImage(
    image: imageProvider,
     ...
    imageBuilder: (context, _) => here i'm using the imageProvider
  );

but would be more slick to have the imageprovider directly in the imageBuilder's constructor

renefloor commented 3 years ago

I see why you'd want this. However, the workaround in CachedNetworkImage is really a workaround and I think it needs some more work to make a decent implementation. The problem is that in this work around the ImageProvider is used to create an Image Widget which you then throw away to create a new image widget. It is not that bad that it can't be used as a workaround, but I think we need to clone the image widget to do the loading and creation of the widget ourselves.

rooscarljohan commented 3 years ago

Thanks. And agree - the workaround isn't really great.

What about providing dual constructors 1) imageProviderBuilder (context, imageProvider) 2) imageBuilder (context, image-widget)

and assess XOR !=null between the two?

then you can decide what to provide, an image-widget OR an imageProvider

renefloor commented 3 years ago

Yes that would be nice, but still we need to rewrite the core flutter image widget to not create an image widget twice. I don't like making such a builder using the workaround hack.