openDocumentFile function
Implementation
Future<DocumentOpenResult> openDocumentFile(
File file, {
Future<OpenResult> Function(String path, {String? type})? defaultOpener,
Future<void> Function(String path, String mimeType, String title)?
chooserOpener,
}) async {
final path = file.path;
final mimeType = mimeTypeForDocumentPath(path);
final opener = defaultOpener ?? OpenFile.open;
if (shouldForceDocumentOpenChooser(path)) {
try {
final chooser = chooserOpener ?? _openWithAndroidChooser;
await chooser(
path,
mimeType ?? 'application/octet-stream',
'Dokument öffnen mit',
);
return const DocumentOpenResult(
DocumentOpenMode.chooser,
'Dokumentauswahl geöffnet.',
);
} on MissingPluginException {
final result = await opener(path, type: mimeType);
return _resultFromOpenFile(result);
} on PlatformException catch (error) {
if (error.code == 'NO_APP') {
return const DocumentOpenResult(
DocumentOpenMode.noApp,
'Keine App zum Öffnen des Dokuments gefunden.',
);
}
rethrow;
}
}
final result = await opener(path, type: mimeType);
return _resultFromOpenFile(result);
}