2021-03-18 19:24:29 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
2021-03-20 15:50:49 +01:00
|
|
|
import 'package:share/share.dart';
|
2021-03-18 19:24:29 +01:00
|
|
|
|
|
|
|
/// A `package:share` wrapper that fallbacks to copying contents to the clipboard
|
|
|
|
/// on platforms that do not support native sharing
|
2021-03-20 15:50:49 +01:00
|
|
|
Future<void> share(
|
|
|
|
String text, {
|
2021-04-09 00:11:44 +02:00
|
|
|
String? subject,
|
|
|
|
Rect? sharePositionOrigin,
|
|
|
|
required BuildContext context,
|
2021-03-20 15:50:49 +01:00
|
|
|
}) async {
|
|
|
|
try {
|
|
|
|
return await Share.share(
|
|
|
|
text,
|
|
|
|
subject: subject,
|
|
|
|
sharePositionOrigin: sharePositionOrigin,
|
|
|
|
);
|
|
|
|
} on MissingPluginException {
|
|
|
|
await Clipboard.setData(ClipboardData(text: text));
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
|
|
const SnackBar(content: Text('Copied data to clipboard!')),
|
|
|
|
);
|
2021-03-18 19:24:29 +01:00
|
|
|
}
|
|
|
|
}
|