我想从我的应用导出CSV文件。我实现了以下简化代码:
import 'package:csv/csv.dart';
import 'package:open_file_plus/open_file_plus.dart';
import 'package:path_provider/path_provider.dart';
// Get directory where a file can be saved
Directory? _externalDocumentsDirectory = await getExternalStorageDirectory();
// Example
String csv = const ListToCsvConverter().convert([
['header_1', 'header_2'],
['value_1', 'value_2']
]);
// Write csv
File f = File("${_externalDocumentsDirectory!.path}/filename.csv");
f.writeAsString(csv);
// Open it
await OpenFile.open(f.path);
从某种意义上说,它将文件保存在所需的位置,如果您使用其他应用程序(如google sheets
)打开该文件,它将按预期工作。
但是最后一个OpenFile.open(f.path);
似乎并不像我预期的那样工作。它提供菜单来选择你想用哪个应用程序打开它。但是google sheets
,xiaomi mi spreadsheets
或reader mi browser
显示它已经损坏。
如果我打印打开它的结果,它只显示消息done
。
如果添加参数type: '.csv'
,则显示为No APP found to open this file
会有什么问题呢?
1条答案
按热度按时间vmpqdwk31#
我遇到了this discussion:
在原来的插件,我正在工作的插件被发现.
提供如下类型后,它现在可以工作了: