Skip to content

Commit 1e52dc4

Browse files
chrisbobbegnprice
authored andcommitted
action_sheet [nfc]: Pull out base class for message action sheet buttons
We're about to add another button, for quote-and-reply zulip#116.
1 parent 0276637 commit 1e52dc4

File tree

1 file changed

+54
-23
lines changed

1 file changed

+54
-23
lines changed

lib/widgets/action_sheet.dart

+54-23
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,61 @@ import 'draggable_scrollable_modal_bottom_sheet.dart';
77
void showMessageActionSheet({required BuildContext context, required Message message}) {
88
showDraggableScrollableModalBottomSheet(
99
context: context,
10-
builder: (BuildContext innerContext) {
10+
builder: (BuildContext _) {
1111
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),
3413
]);
3514
});
3615
}
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

Comments
 (0)