-
-
Notifications
You must be signed in to change notification settings - Fork 899
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
feat: Add network assets package. #2314
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this could be a great package for fetching files from the Internet and then caching them locally -- regardless of the type of the file. Currently it focuses on images, but what about audio files, fire atlas bundles, tiled levels, yarn scripts, custom json, etc?
The task of converting a file into an Image
is quite trivial -- and we can add a helper function fromBytes
into the core Flame Images
class:
Future<Image> fromBytes(String key, Uint8List bytes) {
return (_assets[key] ??= _ImageAsset.future(decodeImageFromList(bytes)))
.retrieveAsync();
}
That is a good idea tbh, I don't think we need to add a fromBytes helper on Flame since the How should we call this then? |
Some more alternatives: |
packages/flame_networks_assets/lib/src/flame_network_assets.dart
Outdated
Show resolved
Hide resolved
( | ||
String url, { | ||
Map<String, String>? headers, | ||
}) => | ||
http.get(Uri.parse(url), headers: headers).then((response) { | ||
return FlameAssetResponse( | ||
statusCode: response.statusCode, | ||
bytes: response.bodyBytes, | ||
); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be a statue method instead of a function defined inline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what you mean about statue
method
/// Flag indicating if files will be cached in the local storage. | ||
final bool cacheInStorage; | ||
|
||
final bool _isWeb; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can't we use kIsWeb
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is used actually, if you look on the constructor, it is the default value for this attribute.
I wrapped it in this attribute to make it easier to mock on tests.
packages/flame_networks_assets/lib/src/flame_network_assets.dart
Outdated
Show resolved
Hide resolved
packages/flame_networks_assets/lib/src/flame_network_assets.dart
Outdated
Show resolved
Hide resolved
packages/flame_networks_assets/lib/src/flame_network_assets.dart
Outdated
Show resolved
Hide resolved
packages/flame_networks_assets/lib/src/flame_network_assets.dart
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lookin' good! Mostly just grammar stuff.
.github/.cspell/flame_dictionary.txt
Outdated
@@ -33,3 +33,4 @@ yarnspinner | |||
рушниці | |||
рушниць | |||
рушниця | |||
unawaited |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this should go in the gamedev_dictionary.txt
?
doc/bridge_packages/flame_network_assets/flame_network_assets.md
Outdated
Show resolved
Hide resolved
doc/bridge_packages/flame_network_assets/flame_network_assets.md
Outdated
Show resolved
Hide resolved
packages/flame_network_assets/lib/src/flame_network_assets.dart
Outdated
Show resolved
Hide resolved
packages/flame_network_assets/lib/src/flame_network_assets.dart
Outdated
Show resolved
Hide resolved
packages/flame_network_assets/lib/src/flame_network_assets.dart
Outdated
Show resolved
Hide resolved
Co-authored-by: Lukas Klingsbo <me@lukas.fyi>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm!
@@ -0,0 +1,27 @@ | |||
name: flame_network_assets | |||
description: Network assets support for Flame. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this will trigger the "package description too short" pub penalty. I think the min is 60 characters. not endorsing unnecessary verbosity but losing points is also bad
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need an empty file at all?
<img src="https://github.com/flame-engine/flame_network_image/workflows/Lint/badge.svg?branch=master&event=push" alt="Test" /> | ||
<a title="Discord" href="https://discord.gg/pxrBmy4" ><img src="https://img.shields.io/discord/509714518008528896.svg" /></a> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not the 4 standard badges? (I know the package hasnt been released yet if you add as soon as it is it will work)
sdk: flutter | ||
|
||
dev_dependencies: | ||
flame_lint: ^0.1.3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use 0.2.0 ?
@@ -0,0 +1,35 @@ | |||
# FlameNetworkAssets | |||
|
|||
`FlameNetworkAssets` is a bridge package focused on providing a solution to fetch, and cache assets |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
`FlameNetworkAssets` is a bridge package focused on providing a solution to fetch, and cache assets | |
`FlameNetworkAssets` is a bridge package focused on providing a solution to fetch and cache assets |
By default, the package relies on the `http` package to make http requests, and `path_provider` | ||
to get the place to store the local cache, to use a different approach for those, use the | ||
optional arguments in the constructor. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By default, the package relies on the `http` package to make http requests, and `path_provider` | |
to get the place to store the local cache, to use a different approach for those, use the | |
optional arguments in the constructor. | |
By default, the package relies on the `http` package to make http requests, and `path_provider` | |
to get the place to store the local cache; to use a different approach for those, use the | |
optional arguments in the constructor. |
```{note} | ||
Check [`flame_network_assets`](https://pub.dev/packages/flame_network_assets) | ||
for a ready to use network assets solution that provides a built in cache. | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could probably be even more persuasive about using the flame_network_assets, and frame importing http "by hand" as an alternative
/// Flag indicating if files will be cached in the local storage. | ||
final bool cacheInStorage; | ||
|
||
final bool _isWeb; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we just set the default value of cacheInStorage to be kIsWeb instead of having two flags?
} | ||
|
||
final response = await _get(url, headers: headers); | ||
if (response.statusCode >= 200 && response.statusCode < 400) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: invert the if
for an early-exit
Description
Adds some documentation and a package that can be used to fetch assets from the network.
Checklist
docs
and added dartdoc comments with///
.examples
ordocs
.Breaking Change?
Related Issues