Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Image.asset with renderFlutterWidget doesn't render Image #178

Open
dario-digregorio opened this issue Nov 5, 2023 · 5 comments
Open

Comments

@dario-digregorio
Copy link

Hi Anton,
first of all thank you really much for your package :)

I am using HomeWidget.renderFlutterWidget to render an image of my Widget which uses Image.asset. For some reason the images are created but they are empty (148B) and some are rendered normally (7,2kB).
image

The Images in the Flutter assets exist and I don't get any exceptions. When I am using another Widget than Image.asset the Images are being rendered and stored correctly. It seems to me that RenderView has a problem with Image.asset Widget.

@ABausG
Copy link
Owner

ABausG commented Nov 6, 2023

Hey Dario!
Glad you found your way here.

So in principle displaying Images using Image.asset should work. I have recently found a similar behaviour in the example I did for Lockscreen Widgets.
Where I observed that when I first call renderFlutterWidget it might not render the Image.asset to the Image. However successive calls to renderFlutterWidget would then render it correctly.
My assumption for this is thus that the Image is not loaded fully when the RenderView captures the canvas.
Could you try if you still encounter this behaviour when you use precacheImage on your Images? https://api.flutter.dev/flutter/widgets/precacheImage.html
If it is indeed the timing issue I suspect this should fix this. Let me know if this works

@dario-digregorio
Copy link
Author

I still encounter the same issue when using precacheImage. But using renderFlutterWidget successive seems to work.

@ABausG
Copy link
Owner

ABausG commented Nov 10, 2023

Hmmm, could you try if try something like the following to make sure the precached ImageProvider is the one used for the widget?

final imgProvider = AssetImage('name');
await precacheImage(imgProvider);
HomeWidget.renderFlutterWidget(Image(image: imgProvider));

Reading a bit through the documentation from Image.asset it might be that there is some scaling going on when just using Image.asset

@dario-digregorio
Copy link
Author

Did not work either. Just the hack of calling renderFlutterWidget twice seems to work.

@wxkly8888
Copy link

Hmmm, could you try if try something like the following to make sure the precached ImageProvider is the one used for the widget?

final imgProvider = AssetImage('name');
await precacheImage(imgProvider);
HomeWidget.renderFlutterWidget(Image(image: imgProvider));

Reading a bit through the documentation from Image.asset it might be that there is some scaling going on when just using Image.asset
This solves my problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants