I want to export a CSV file from my app. I implemented the following simplified code:
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);
This works as expected in the sense that it saves the file at the desired location, and if you use another app like google sheets
to open that file it works.
But the last piece OpenFile.open(f.path);
does not seem to work as I expect. It lunches the menu to select with which app you want to open it. But google sheets
, xiaomi mi spreadsheets
or reader mi browser
show it is corrupt.
If I print the result of opening it just shows the message done
.
If I add the paramters type: '.csv'
it shws No APP found to open this file
What can be wrong?