@@ -9,28 +9,62 @@ void showMessageActionSheet({required BuildContext context, required Message mes
9
9
context: context,
10
10
builder: (BuildContext innerContext) {
11
11
return Column (children: [
12
- MenuItemButton (
13
- leadingIcon: Icon (Icons .adaptive.share),
14
- onPressed: () async {
15
- // Close the message action sheet; we're about to show the share
16
- // sheet. (We could do this after the sharing Future settles, but
17
- // on iOS I get impatient with how slowly our action sheet
18
- // dismisses in that case.)
19
- // TODO(#24): Fix iOS bug where this call causes the keyboard to
20
- // reopen (if it was open at the time of this
21
- // `showMessageActionSheet` call) and cover a large part of the
22
- // share sheet.
23
- Navigator .of (innerContext).pop ();
24
-
25
- // TODO: to support iPads, we're asked to give a
26
- // `sharePositionOrigin` param, or risk crashing / hanging:
27
- // https://pub.dev/packages/share_plus#ipad
28
- // Perhaps a wart in the API; discussion:
29
- // https://github.com/zulip/zulip-flutter/pull/12#discussion_r1130146231
30
- // TODO: Share raw Markdown, not HTML
31
- await Share .shareWithResult (message.content);
32
- },
33
- child: const Text ('Share' )),
12
+ ShareButton (message: message, bottomSheetContext: innerContext),
34
13
]);
35
14
});
36
15
}
16
+
17
+ abstract class MessageActionSheetMenuItemButton extends StatelessWidget {
18
+ MessageActionSheetMenuItemButton ({
19
+ super .key,
20
+ required this .message,
21
+ required this .bottomSheetContext,
22
+ }) : assert (bottomSheetContext.findAncestorWidgetOfExactType <BottomSheet >() != null );
23
+
24
+ IconData get icon;
25
+ String get label;
26
+ VoidCallback get onPressed;
27
+
28
+ final Message message;
29
+ final BuildContext bottomSheetContext;
30
+
31
+ @override
32
+ Widget build (BuildContext context) {
33
+ return MenuItemButton (
34
+ leadingIcon: Icon (icon),
35
+ onPressed: onPressed,
36
+ child: Text (label));
37
+ }
38
+ }
39
+
40
+ class ShareButton extends MessageActionSheetMenuItemButton {
41
+ ShareButton ({
42
+ super .key,
43
+ required super .message,
44
+ required super .bottomSheetContext,
45
+ });
46
+
47
+ @override IconData get icon => Icons .adaptive.share;
48
+
49
+ @override String get label => 'Share' ;
50
+
51
+ @override VoidCallback get onPressed => () async {
52
+ // Close the message action sheet; we're about to show the share
53
+ // sheet. (We could do this after the sharing Future settles, but
54
+ // on iOS I get impatient with how slowly our action sheet
55
+ // dismisses in that case.)
56
+ // TODO(#24): Fix iOS bug where this call causes the keyboard to
57
+ // reopen (if it was open at the time of this
58
+ // `showMessageActionSheet` call) and cover a large part of the
59
+ // share sheet.
60
+ Navigator .of (bottomSheetContext).pop ();
61
+
62
+ // TODO: to support iPads, we're asked to give a
63
+ // `sharePositionOrigin` param, or risk crashing / hanging:
64
+ // https://pub.dev/packages/share_plus#ipad
65
+ // Perhaps a wart in the API; discussion:
66
+ // https://github.com/zulip/zulip-flutter/pull/12#discussion_r1130146231
67
+ // TODO: Share raw Markdown, not HTML
68
+ await Share .shareWithResult (message.content);
69
+ };
70
+ }
0 commit comments