shareFile static method

Future<String> shareFile({
  1. required String filePath,
  2. required String mimeType,
})
override

Shares a single file to social media or system share UI.

filePath is the path to the file to share (required). mimeType specifies the MIME type of the file (e.g., 'image/png').

Returns a Future that completes with a string indicating the result: 'success' if the share operation was successful, or an error message if it failed.

Example:

final result = await MethodChannelCustomShare.shareFile(
  filePath: 'path/to/image.png',
  mimeType: 'image/png',
);
print(result); // Prints 'success' or 'Error sharing file: ...'

Throws a PlatformException if the native platform share operation fails.

Implementation

static Future<String> shareFile({
  required String filePath,
  required String mimeType,
}) async {
  try {
    return await methodChannel.invokeMethod('shareFile', {
          'filePath': filePath,
          'mimeType': mimeType,
        }) ??
        'success';
  } catch (e) {
    return 'Error sharing file: $e';
  }
}