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