我检查了错别字。我在 pubspec.yaml 资产部分有文件。我不明白为什么它找不到不为空的文件。
错误信息:
执行热重启...等待来自 Chrome 调试服务的连接...在 337 毫秒内重新启动应用程序。尝试加载资产时出错:Flutter Web 引擎无法获取 >“assets/assets/rungFile.txt”。 HTTP 请求成功,但服务器响应 HTTP >status 404。错误:无法加载资产:“assets/rungFile.txt”。资产不存在或数据为空。
void readFile() async {
String data = await rootBundle.loadString('assets/rungFile.txt');
List<String> lines = const LineSplitter().convert(data);
for (String line in lines) {
List<String> words = line.split(',');
Rung rung = Rung(name: words[0], rungId: words[1], done: bool.parse(words[2]),
boldTitle: bool.parse(words[3]), info: words[4]);
Rung.myList.add(rung);
}
}
重新启动 Android Studio。问题消失了。