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 bepackages/package_name/assets/translations/en.json
. Note thatpackages
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?"