2023-02-08 18:16:12 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:share_plus/share_plus.dart';
|
2023-02-13 18:41:18 +00:00
|
|
|
import 'package:cross_file/cross_file.dart';
|
2023-02-08 18:16:12 +00:00
|
|
|
|
|
|
|
class ShareUtil {
|
2023-02-13 18:41:18 +00:00
|
|
|
static const _mimeType = 'application/*';
|
2023-02-08 18:16:12 +00:00
|
|
|
|
2023-02-13 18:41:18 +00:00
|
|
|
static void share({required String text, required BuildContext context}) {
|
2023-02-08 18:16:12 +00:00
|
|
|
Share.share(
|
|
|
|
text,
|
2023-02-13 18:41:18 +00:00
|
|
|
sharePositionOrigin: _sharePosition(context),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Future<void> shareFile({
|
|
|
|
required String filePath,
|
|
|
|
required String fileName,
|
|
|
|
required BuildContext context,
|
|
|
|
}) async {
|
|
|
|
Share.shareXFiles(
|
|
|
|
<XFile>[
|
|
|
|
XFile(
|
|
|
|
filePath,
|
|
|
|
name: fileName,
|
|
|
|
mimeType: _mimeType,
|
|
|
|
)
|
|
|
|
],
|
|
|
|
sharePositionOrigin: _sharePosition(context),
|
2023-02-08 18:16:12 +00:00
|
|
|
);
|
|
|
|
}
|
2023-02-13 18:41:18 +00:00
|
|
|
|
|
|
|
static Rect? _sharePosition(BuildContext context) {
|
|
|
|
final box = context.findRenderObject() as RenderBox?;
|
|
|
|
|
|
|
|
return box!.localToGlobal(Offset.zero) & box.size;
|
|
|
|
}
|
|
|
|
}
|