I have user Image.asset for a png, but have remarked that image loose quality, how to preserve same quality in real devices.
Thanks in advance.
Image is a StatefulWidget and Image. asset is just a named constructor, you can use it directly on your widget tree. AssetImage is an ImageProvider which is responsible for obtaining the image of the specified path. If you check the source code of the Image.
The Flutter app supports many image formats, such as JPEG, WebP, PNG, GIF, animated WebP/GIF, BMP, and WBMP.
In my case, the problem was due to a bad configuration of the image resolution system.
On the one hand, you have to specify the different resolutions in the assets folder.
assets/my_icon.png
assets/2.0x/my_icon.png
assets/3.0x/my_icon.png
On the other hand, you have to declare these variants in the pubspec.yaml
file.
flutter:
assets:
- assets/
- assets/2.0x/
- assets/3.0x/
More information in the Flutter docs.
TIP: If you export the images from another program (Adobe XD for example), you can automate this task with the image_res package.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With