shareText static method

Future<String> shareText({
  1. required String text,
})
override

Shares a text message to social media or system share UI.

text is the main content to share (required).

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.shareText(text: 'Hello!');
print(result); // Prints 'success' or 'Error sharing text: ...'

Throws a PlatformException if the native platform share operation fails.

Implementation

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