我的文件endpoints.json
在/WORKPLACE_DIR/assets/json/endpoints.json
中
{
"key": "value"
}
我已经更新了我的pubspec.yaml
assets:
- assets/json/endpoints.json
单位:/tests/some_test.dart
我知道
test('my test', () async {
final endpoints = json.decode(await rootBundle.loadString("assets/json/endpoints.json"));
}
它仍然给出错误
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
我试过flutter clean
,但它仍然给出这个错误。我不知道该怎么做。
3条答案
按热度按时间ruarlubt1#
我在图片上也遇到过类似的问题。原因很简单,我跳过了“assets:“之前的标签。如果单词“flutter:“和“assets:“在pubspec.yaml文件中处于同一级别,您将得到“无法加载资产”错误。因此,只需在“assets:“和“- assets/json/endpoints.json”之前添加标签。
zynd9foi2#
您好,也许将资产添加到pubspec.yaml将有助于解决这个问题。
qeeaahzv3#
如果在子模块中,则需要将
packages/your_submodule_name/
放在assets路径前面例如: