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

Include package in AssetGenImage path property #248

Closed
kolotum opened this issue May 31, 2022 · 7 comments
Closed

Include package in AssetGenImage path property #248

kolotum opened this issue May 31, 2022 · 7 comments
Assignees
Milestone

Comments

@kolotum
Copy link
Contributor

kolotum commented May 31, 2022

Similiar to AssetImage's keyName property it would be helpful to change AssetGenImage's path property to include package so we can hide the package name inside of AssetGenImage:

-  String get path => _assetName;
+  String get path =>
+      _package == null ? _assetName : 'packages/$_package/$_assetName';

_package could be generated, e.g.
final String? _package = 'example_resources';

without package_parameter_enabled: true:
final String? _package;

SvgGenImage could be changed accordingly.

@lcdsmao
Copy link
Member

lcdsmao commented Jun 1, 2022

Can you tell me your use case here?

so we can hide the package name inside of AssetGenImage

What's the benefit of this?

@kolotum
Copy link
Contributor Author

kolotum commented Jun 2, 2022

What's the benefit of this?

The reason is to encapsulate the package name so we can use the AssetGenImage without parameter, e.g.
use Image.asset(res.Assets.images.flutter3.path) instead of Image.asset(res.Assets.images.flutter3.path, package: 'example_resources')
(Just an example, we would use res.Assets.images.flutter3.image() instead of Image.asset(...) ).

In other cases there is no package parameter available. One use case is to load the data of the AssetGenImage directly and convert it into ui.Image which is used in our particle system, e.g.:

final imageData = await rootBundle.load(res.Assets.images.flutter3.path);
final uiImage = await decodeImageFromList(Uint8List.view(imageData.buffer));

@renancaraujo
Copy link

On the Flame engine we don't use widgets. Having a generated path with the package name would be helpful. It was possible to get that before #229 (via .keyName property that AssetImage has).

@wasabeef
Copy link
Member

wasabeef commented Jun 8, 2022

@kolotum @renancaraujo

When package_parameter_enabled is true, Can you solve this problem by generating the following?

String get path => _assetName;

// THIS
String get keyName => 'packages/$packageName/\$_assetName'; // 'packages/example_resources/assets/images/flutter3.jpg'

or do you need always it? when package_parameter_enabled is false.

@wasabeef wasabeef self-assigned this Jun 8, 2022
@wasabeef wasabeef added this to the 4.3.0 milestone Jun 8, 2022
@kolotum
Copy link
Contributor Author

kolotum commented Jun 8, 2022

@kolotum @renancaraujo

When package_parameter_enabled is true, Can you solve this problem by generating the following?

String get path => _assetName;

// THIS
String get keyName => 'packages/$packageName/\$_assetName'; // 'packages/example_resources/assets/images/flutter3.jpg'

or do you need always it? when package_parameter_enabled is false.

If you would like to keep the path value to not break the current implementations it is okay to introduce a new getter keyName.

I would still prefer a property where I do not need to now the value of package_parameter_enabled.

So I think of something like

String get keyName =>  _package == null ? _assetName : 'packages/$packageName/$_assetName';

or

// when package_parameter_enabled is false
String get keyName => _assetName;

// when package_parameter_enabled is true:
String get keyName =>  'packages/$packageName/$_assetName';

@wasabeef
Copy link
Member

wasabeef commented Jun 8, 2022

@kolotum
Thank you for your response. I'd like to keep the path variable, so I will do the following (a bit redundant).

When package_parameter_enabled = true

String get path => _assetName;

String get keyName => 'packages/$packageName/\$_assetName';

When package_parameter_enabled = false

String get path => _assetName;

String get keyName => _assetName;

This was referenced Jun 8, 2022
@wasabeef
Copy link
Member

wasabeef commented Jun 9, 2022

@kolotum @renancaraujo
I just released v4.3.0, Thank you all.

@AlexV525 AlexV525 closed this as completed Mar 7, 2024
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

5 participants