My file endpoints.json
is in /WORKPLACE_DIR/assets/json/endpoints.json
{
"key": "value"
}
I have updated my pubspec.yaml
assets:
- assets/json/endpoints.json
In /tests/some_test.dart
I do
test('my test', () async {
final endpoints = json.decode(await rootBundle.loadString("assets/json/endpoints.json"));
}
It still gives an error
ERROR: Unable to load asset: assets/json/endpoints.json
package:flutter/src/services/asset_bundle.dart 221:7 PlatformAssetBundle.load
===== asynchronous gap ===========================
dart:async _AsyncAwaitCompleter.completeError
package:flutter/src/services/asset_bundle.dart PlatformAssetBundle.load
===== asynchronous gap ===========================
dart:async _asyncThenWrapperHelper
package:flutter/src/services/asset_bundle.dart PlatformAssetBundle.load
package:flutter/src/services/asset_bundle.dart 67:33 AssetBundle.loadString
I have tried flutter clean
but it still gives this error. I am not sure what to do.
A flutter app when built has both assets (resources) and code. Assets are available and deployed during runtime. The asset is a file that can include static data, configuration files, icons, and images. The Flutter app supports many image formats, such as JPEG, WebP, PNG, GIF, animated WebP/GIF, BMP, and WBMP.
Applications have a rootBundle, which contains the resources that were packaged with the application when it was built. To add resources to the rootBundle for your application, add them to the assets subsection of the flutter section of your application's pubspec. yaml manifest.
I had similar problem with images. The reason was simple, I skipped the tab before "assets:". If the words "flutter:" and "assets:" are on the same level in your pubspec.yaml file you will get the "unable to load asset" error. So just add the tab before "assets:" and "- assets/json/endpoints.json".
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