FlutterGen / flutter_gen

The Flutter code generator for your assets, fonts, colors, … — Get rid of all String-based APIs.
https://pub.dev/packages/flutter_gen
MIT License
1.44k stars 142 forks source link

[BUG]: Unable to find the assets when used in package or module #398

Closed rddewan closed 1 week ago

rddewan commented 1 year ago

Is there an existing issue for this?

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

rajeevjaiswal commented 1 year ago

any update on this issue?

NeilPotot-Xam commented 12 months ago

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.

image
NeilPotot-Xam commented 12 months ago

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.

image

Solved it by doing the following, can finally read the assets from packages. Hope this helps

image

Generated output

image

Sample usage

image
rddewan commented 12 months ago

@NeilPotot-Xam Looks good any doc reference on it? I cant find it

AlexV525 commented 1 week ago

package will be generated if you enable package_parameter_enabled. See the updated README.