我正在寻找一种可以监听对文件进行的更改的方法。例如,有一个名为“x.json”的文件,我将在其中读取和写入该文件。
我会写这样的数据, write['key']['c'] = 3 //只是为了表示目的。
{
"key":{
"a":1,
"b":2,
"c":3
}
}
Run Code Online (Sandbox Code Playgroud)
由于 'c':3 已添加到 'key',我希望它反映在我的应用程序中。即:读
我的代码:
final directory = await getApplicationDocumentsDirectory();
File xfile = File('${directory.path}/x.json');
_fileSubscription = xfile.watch().listen((FileSystemEvent event) {
if (mounted) {
setState(() {
currentXFileContent= jsonDecode(xfile.readAsStringSync());
print('Within stream, currentXFileContent: $currentXFileContent');
});
}
});
Run Code Online (Sandbox Code Playgroud)
我收到这条消息
未处理的异常:FileSystemException:此平台不支持文件系统监视,路径 = ''
我该如何解决这个问题?
| 归档时间: |
|
| 查看次数: |
657 次 |
| 最近记录: |