open method
Opens a local file using native presentation.
Implementation
@override
Future<OpenFileResult> open(
String filePath, {
String? title,
String? mimeType,
}) async {
try {
final response = await methodChannel.invokeMethod<Object?>('open', {
'path': filePath,
'title': title,
'mimeType': mimeType,
});
if (response is! Map) {
return const OpenFileResult(
OpenFileStatus.error,
'Invalid native response',
);
}
return OpenFileResult.fromMap(response.cast<Object?, Object?>());
} on PlatformException catch (error) {
return OpenFileResult(OpenFileStatus.error, error.message ?? error.code);
} on MissingPluginException {
return const OpenFileResult(
OpenFileStatus.error,
'Plugin not registered; rebuild and restart the app',
);
} catch (error) {
return OpenFileResult(
OpenFileStatus.error,
'Could not decode native response: $error',
);
}
}