feat: Added method Images.ready()#1441
Conversation
spydon
left a comment
There was a problem hiding this comment.
Looks good, docs are missing though
|
Can't you just use |
You can. But that requires all images to be loaded up-front from a single place, whereas it could be more convenient to split loading into multiple parts. So, |
But I get that it might feel bit strange to use it like that. But I dont think this is the way to go either. Also I think the name It is more of a |
|
One problem with Future<void> onLoad() async {
add(Background());
add(Player());
add(Enemy());
add(Hud());
await images.ready();
}Here the
You're right that if we think of |
|
|
||
| It has to be png files and they can have transparency. | ||
| Images can be in any format supported by Flutter, which include: JPEG, WebP, PNG, GIF, animated GIF, | ||
| animated WebP, BMP, and WBMP. Other formats would require additional libraries. For example, SVG |
There was a problem hiding this comment.
is this true of all platforms? (mobile, web, desktop)
There was a problem hiding this comment.
Here's what the Flutter docs say:
// Update this list when changing the list of supported codecs.
/// {@template dart.ui.imageFormats}
/// JPEG, PNG, GIF, Animated GIF, WebP, Animated WebP, BMP, and WBMP. Additional
/// formats may be supported by the underlying platform. Flutter will
/// attempt to call platform API to decode unrecognized formats, and if the
/// platform API supports decoding the image Flutter will be able to render it.
/// {@endtemplate}So this looks like a minimal set that's supported on all platforms, plus some additional formats may be supported on each specific platform.
luanpotter
left a comment
There was a problem hiding this comment.
@st-pasha I see, good point.
LGTM
Description
Added method
Images.ready()to await for all images that are currently loading. For example, this allows the user to writeIn addition, multiple small improvements to the
Imagesclass:_loadedFiles->_assets, which reflects the fact that this map also contains images that have not been loaded yet._ImageAssetthat does not require a future._ImageAsset.dispose()for more thorough disposal: now if there is a pending future to load the image, that image will get disposed as well when the future completes.Images.fromCache(): now it distinguishes between image not added to the cache, or image added but not loaded yet._futurewill be garbage-collected, leaving only the image behind.Checklist
fix:,feat:,docs:etc).docsand added dartdoc comments with///.examples.Breaking Change
Related Issues