颤振:无法加载文本资产

时间:2018-09-27 09:55:52

标签: dart flutter

我的文件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,但仍然出现此错误。我不确定该怎么办。

2 个答案:

答案 0 :(得分:0)

我在图片上也有类似的问题。原因很简单,我跳过了“资产:”之前的标签。如果在pubspec.yaml文件中单词“ flutter:”和“ assets:”处于同一级别,则将出现“无法加载资产”错误。因此,只需在“ assets:”和“ -assets / json / endpoints.json”之前添加标签即可。

答案 1 :(得分:0)

您好,也许将资产添加到 pubspec.yaml 将有助于解决问题。 enter image description here