Flutter:无法使用rootBundle读取本地json文件



代码:

import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/services.dart';
void main() {
String abiStringFile="";
String path = "assets/data.json";
setUp(() async {
abiStringFile = await rootBundle.loadString(path);
});
test("Run Please", (){
print(abiStringFile);
});
}

错误:

Null check operator used on a null value.
Problem in PlatfromAssetBundle.load from services/asset_bundle.dart:223

pubspec.yaml文件

flutter:
uses-material-design: true
assets:
- assets/data.json

尝试在SetUp():的开头写入

TestWidgetsFlutterBinding.ensureInitialized();

相关内容

  • 没有找到相关文章

最新更新