Skip to content Skip to sidebar Skip to footer

How To Load A File From A Specific Package In Flutter?

Here's my folder structure for the package core : /pubspec.yaml /assets |-images |-lang |- en.json |- hi.json I have a similar structure for another module ca

Solution 1:

when building a package:

  • put your assets in the assets folder of the package as usual
  • add the assets/translations/ to pubspec, don't forget the last / as it means the whole dir
  • when using rootBundle.loadAsString or the likes the path will be packages/package_name/assets/translations/en.json. Note that packages is plural.

Solution 2:

Turned out that when we import assets inside packages , we need to include specific files too and just a folder include doesn't work.

So doing the following fixed it :D

flutter:
  assets:
    - packages/core/assets/lang/en.json
    - packages/core/assets/lang/sp.json
    - packages/core/assets/images/myimage.png

Post a Comment for "How To Load A File From A Specific Package In Flutter?"