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

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

Open
2 tasks done
rddewan opened this issue Jun 14, 2023 · 4 comments
Open
2 tasks done

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

rddewan opened this issue Jun 14, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@rddewan
Copy link

rddewan commented Jun 14, 2023

Is there an existing issue for this?

  • 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

  • I agree to follow this project's Code of Conduct
@rddewan rddewan added the bug Something isn't working label Jun 14, 2023
@rajeevjaiswal
Copy link

any update on this issue?

@NeilPotot-Xam
Copy link

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
Copy link

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
Copy link
Author

rddewan commented Jul 12, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants