share method

  1. @override
Future<void> share(
  1. String text, {
  2. String? subject,
  3. Rect? sharePositionOrigin,
})
override

Share text.

Implementation

@override
Future<void> share(
  String text, {
  String? subject,
  Rect? sharePositionOrigin,
}) async {
  final queryParameters = {
    if (subject != null) 'subject': subject,
    'body': text,
  };

  // see https://github.com/dart-lang/sdk/issues/43838#issuecomment-823551891
  final uri = Uri(
    scheme: 'mailto',
    query: queryParameters.entries
        .map((e) =>
            '${Uri.encodeComponent(e.key)}=${Uri.encodeComponent(e.value)}')
        .join('&'),
  );

  if (await canLaunchUrl(uri)) {
    await launchUrl(uri);
  } else {
    throw Exception('Unable to share on windows');
  }
}