【发布时间】:2018-12-27 12:33:32
【问题描述】:
我一直在编写 Flutter 中的一段代码,以将指定的变量保存到文本文件中。这只需按下一个按钮即可。为了实现这一点,我使用 path_provider 依赖项
代码如下所示:
trailing: new IconButton(
icon: new Icon(Icons.add),
onPressed: () async {
Directory appDocDir = await getApplicationDocumentsDirectory();
String appDocPath = appDocDir.path;
new File('$appDocPath/my_file.txt')
.writeAsStringSync('myVar: $_currencies');
print(myFile.absolute.path);
}
),
在这里传递我的所有代码会很困难,因为要执行稳定的构建,我需要大量代码。 相反,我在这里提供了一个 Git 存储库: https://github.com/Jak3-02/myproject2
我希望创建一个名为 my_file.txt 的新文件,但我找不到它。另外,我希望以下代码能够返回已保存到文件中的内容,以便查看文件是否已创建。
print(myFile.absolute.path);
但是,我得到了错误:
[dart] Undefined name 'myFile'
我希望输出类似于myVar: Bitcoin 或myVar: Ethereum,但是当我遇到这些错误时,我显然无法对此进行测试。
【问题讨论】:
标签: android ios dart storage flutter