openFile function
dynamic
openFile(
- Uint8List bytes,
- FileOpenerFileType fileType, {
- String baseFileName = 'temp',
- bool preferDownload = true,
Implementation
openFile(
Uint8List bytes,
FileOpenerFileType fileType, {
String baseFileName = 'temp',
bool preferDownload = true,
}) async {
// Get temporary directory
final tempDir = await getTemporaryDirectory();
// Assume FileOpenerFileType has an 'extension' property, e.g., "pdf", "txt", etc.
final filePath = '${tempDir.path}/$baseFileName.${fileType.extension}';
final file = File(filePath);
// Write bytes to the file
await file.writeAsBytes(bytes, flush: true);
// Open the file with the default app
await OpenFile.open(file.path);
}