浏览代码

Fix share dialog position for bottom bar button

Neeraj Gupta 3 年之前
父节点
当前提交
fc2e62b325
共有 2 个文件被更改,包括 23 次插入4 次删除
  1. 3 1
      lib/ui/fading_bottom_bar.dart
  2. 20 3
      lib/utils/share_util.dart

+ 3 - 1
lib/ui/fading_bottom_bar.dart

@@ -33,6 +33,7 @@ class FadingBottomBar extends StatefulWidget {
 
 class FadingBottomBarState extends State<FadingBottomBar> {
   bool _shouldHide = false;
+  final GlobalKey shareButtonKey = GlobalKey();
 
   @override
   Widget build(BuildContext context) {
@@ -131,11 +132,12 @@ class FadingBottomBarState extends State<FadingBottomBar> {
           child: Padding(
             padding: const EdgeInsets.only(top: 12, bottom: 12),
             child: IconButton(
+              key: shareButtonKey,
               icon: Icon(Platform.isAndroid
                   ? Icons.share_outlined
                   : CupertinoIcons.share),
               onPressed: () {
-                share(context, [widget.file]);
+                share(context, [widget.file], shareButtonKey: shareButtonKey);
               },
             ),
           ),

+ 20 - 3
lib/utils/share_util.dart

@@ -11,12 +11,13 @@ import 'package:photos/models/file_type.dart';
 import 'package:photos/utils/dialog_util.dart';
 import 'package:photos/utils/exif_util.dart';
 import 'package:photos/utils/file_util.dart';
+import 'package:photos/utils/toast_util.dart';
 import 'package:receive_sharing_intent/receive_sharing_intent.dart';
 import 'package:share_plus/share_plus.dart';
 
 final _logger = Logger("ShareUtil");
 // share is used to share media/files from ente to other apps
-Future<void> share(BuildContext context, List<File> files) async {
+Future<void> share(BuildContext context, List<File> files, {GlobalKey shareButtonKey}) async {
   final dialog = createProgressDialog(context, "preparing...");
   await dialog.show();
   final List<Future<String>> pathFutures = [];
@@ -31,14 +32,30 @@ Future<void> share(BuildContext context, List<File> files) async {
   }
   final paths = await Future.wait(pathFutures);
   await dialog.hide();
-  final Size size = MediaQuery.of(context).size;
   return Share.shareFiles(
     paths,
     // required for ipad https://github.com/flutter/flutter/issues/47220#issuecomment-608453383
-    sharePositionOrigin: Rect.fromLTWH(0, 0, size.width, size.height / 2),
+    sharePositionOrigin: shareButtonRect(context, shareButtonKey),
   );
 }
 
+Rect shareButtonRect(BuildContext context, GlobalKey shareButtonKey) {
+  Size size = MediaQuery
+      .of(context)
+      .size;
+  RenderBox renderBox = shareButtonKey?.currentContext?.findRenderObject();
+  if (renderBox == null) {
+    return Rect.fromLTWH(0, 0, size.width, size.height / 2);
+  }
+  size = renderBox.size;
+  Offset position = renderBox.localToGlobal(Offset.zero);
+  showToast('using soln');
+  return Rect.fromCenter(
+    center: position + Offset(size.width / 2, size.height / 2),
+    width: size.width,
+    height: size.height,
+  );
+}
 Future<void> shareText(String text) async {
   return Share.share(text);
 }