Skip to content

Commit c9ac25c

Browse files
committed
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 19999f4 commit c9ac25c

File tree

1 file changed

+56
-22
lines changed

1 file changed

+56
-22
lines changed

lib/widgets/action_sheet.dart

+56-22
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,62 @@ void showMessageActionSheet({required BuildContext context, required Message mes
99
context: context,
1010
builder: (BuildContext innerContext) {
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, bottomSheetContext: innerContext),
3413
]);
3514
});
3615
}
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

Comments
 (0)