flutter_gen
flutter_gen copied to clipboard
[BUG]: Unable to find the assets when used in package or module
Is there an existing issue for this?
- [X] I have searched the existing issues
Version
^5.3.1
Command type
build_runner (Default)
What happened?
I have a modular architecture with multiple packages and in one of my packages i added a assets folder assets/images/headphone.jpg once the build runner is generate a assets.gen.dart
class $AssetsImagesGen {
const $AssetsImagesGen();
/// File path: assets/images/headphone.jpeg
AssetGenImage get headphone =>
const AssetGenImage('assets/images/headphone.jpeg');
/// List of all assets
List<AssetGenImage> get values => [headphone];
}
Since the file path is const assets/images/headphone.jpeg it can't find it the actual file path should be packages/product/assets/images/headphone.jpeg
Relevant a pubspec.yaml.
name: product
description: A new Flutter package project.
version: 0.0.1
publish_to: none
homepage:
environment:
sdk: '>=3.0.2 <4.0.0'
flutter: ">=1.17.0"
dependencies:
flutter:
sdk: flutter
common:
path: ../common
core:
path: ../core
cart:
path: ../cart
dependency_overrides:
intl: ^0.17.0
collection: ^1.17.1
test_api: ^0.5.1
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^2.0.1
hive_generator: ^2.0.0
hive_test: ^1.0.1
build_runner: ^2.3.2
envied_generator: ^0.3.0
retrofit_generator: '>=4.0.0 <5.0.0'
json_serializable: '^6.6.1'
freezed: ^2.3.2
riverpod_generator: ^2.2.0
mockito: ^5.4.0
flutter_gen_runner: ^5.3.1
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter packages.
flutter:
uses-material-design: true
# To add assets to your package, add an assets section, like this:
assets:
- assets/images/
Relevant log output
No response
Code of Conduct
- [X] I agree to follow this project's Code of Conduct
any update on this issue?
Found out that if you specify the package name while the asset comes from a package or module, the asset will be displayed. Is there a way to make this more convenient? I mean, to needlessly put the package name each time you use an asset from a package/module.
Found out that if you specify the package name while the asset comes from a package or module, the asset will be displayed. Is there a way to make this more convenient? I mean, to needlessly put the package name each time you use an asset from a package/module.
![]()
Solved it by doing the following, can finally read the assets from packages. Hope this helps
Generated output
Sample usage
@NeilPotot-Xam Looks good any doc reference on it? I cant find it
package will be generated if you enable package_parameter_enabled. See the updated README.