I have a project that consumes another package on the drive using a relative path:
project1 (setup as a full flutter project with flutter create project1)
project2 (setup with flutter create --template=package
project1's packages.yaml does this: dependancies: project1: path: ../project2
project2's packages.yaml does this:
flutter: assets: - lang/en.json
Which works and everything sees everything else and there is no complaint about that path for the asset and I've verified that it has exactly 2 spaces before assets: and exactly 4 actual spaces beofre - lang/en.json
The problem occurs when project2 tries to load lang/en.json like this in code form project2:
final jsonString = await rootBundle.loadString('lang/en.json');
I get an "asset could not be loaded ${key}" on the loadString function.
if however I take exactly the same code and put it on project1 and copy the folder exactly and copy the exact same asset tag in packages.yaml, project1 has no problem loading the file. If I even leave the asset links on the project1 then project2 can load them just fine too.
Is this a bug, or am I doing something wrong with the package template version?
I have same issue. and I found the solution: In project2, do some steps as below:
flutter:
assets:
- assets/lang/vi.json
- assets/lang/en.json
await rootBundle.loadString('packages/language_pack/assets/langen.json');
Note that packages is plural and language_pack is package name
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With