@@ -23,6 +23,90 @@ import 'store.dart';
23
23
import 'text.dart' ;
24
24
import 'theme.dart' ;
25
25
26
+ abstract class ActionSheetMenuItemButton extends StatelessWidget {
27
+ const ActionSheetMenuItemButton ({super .key, required this .pageContext});
28
+
29
+ IconData get icon;
30
+ String label (ZulipLocalizations zulipLocalizations);
31
+
32
+ /// Called when the button is pressed, after dismissing the action sheet.
33
+ ///
34
+ /// If the action may take a long time, this method is responsible for
35
+ /// arranging any form of progress feedback that may be desired.
36
+ ///
37
+ /// For operations that need a [BuildContext] , see [pageContext] .
38
+ void onPressed ();
39
+
40
+ /// A context within the [MessageListPage] this action sheet was
41
+ /// triggered from.
42
+ final BuildContext pageContext;
43
+
44
+ /// The [MessageListPageState] this action sheet was triggered from.
45
+ ///
46
+ /// Uses the inefficient [BuildContext.findAncestorStateOfType] ;
47
+ /// don't call this in a build method.
48
+ MessageListPageState findMessageListPage () {
49
+ assert (pageContext.mounted,
50
+ 'findMessageListPage should be called only when pageContext is known to still be mounted' );
51
+ return MessageListPage .ancestorOf (pageContext);
52
+ }
53
+
54
+ void _handlePressed (BuildContext context) {
55
+ // Dismiss the enclosing action sheet immediately,
56
+ // for swift UI feedback that the user's selection was received.
57
+ Navigator .of (context).pop ();
58
+
59
+ assert (pageContext.mounted);
60
+ onPressed ();
61
+ }
62
+
63
+ @override
64
+ Widget build (BuildContext context) {
65
+ final designVariables = DesignVariables .of (context);
66
+ final zulipLocalizations = ZulipLocalizations .of (context);
67
+ return MenuItemButton (
68
+ trailingIcon: Icon (icon, color: designVariables.contextMenuItemText),
69
+ style: MenuItemButton .styleFrom (
70
+ padding: const EdgeInsets .symmetric (vertical: 12 , horizontal: 16 ),
71
+ foregroundColor: designVariables.contextMenuItemText,
72
+ splashFactory: NoSplash .splashFactory,
73
+ ).copyWith (backgroundColor: WidgetStateColor .fromMap ({
74
+ WidgetState .pressed: designVariables.contextMenuCancelPressedBg,
75
+ ~ WidgetState .pressed: designVariables.contextMenuCancelBg,
76
+ })),
77
+ onPressed: () => _handlePressed (context),
78
+ child: Text (label (zulipLocalizations),
79
+ style: const TextStyle (fontSize: 20 , height: 24 / 20 )
80
+ .merge (weightVariableTextStyle (context, wght: 600 )),
81
+ ));
82
+ }
83
+ }
84
+
85
+ class ActionSheetCancelButton extends StatelessWidget {
86
+ const ActionSheetCancelButton ({super .key});
87
+
88
+ @override
89
+ Widget build (BuildContext context) {
90
+ final designVariables = DesignVariables .of (context);
91
+ return TextButton (
92
+ style: TextButton .styleFrom (
93
+ padding: const EdgeInsets .all (10 ),
94
+ foregroundColor: designVariables.contextMenuCancelText,
95
+ shape: RoundedRectangleBorder (borderRadius: BorderRadius .circular (7 )),
96
+ splashFactory: NoSplash .splashFactory,
97
+ ).copyWith (backgroundColor: WidgetStateColor .resolveWith ((states) =>
98
+ designVariables.contextMenuCancelBg.withFadedAlpha (
99
+ states.contains (WidgetState .pressed) ? 0.20 : 0.15 ))),
100
+ onPressed: () {
101
+ Navigator .pop (context);
102
+ },
103
+ child: Text (ZulipLocalizations .of (context).dialogCancel,
104
+ style: const TextStyle (fontSize: 20 , height: 24 / 20 )
105
+ .merge (weightVariableTextStyle (context, wght: 600 ))),
106
+ );
107
+ }
108
+ }
109
+
26
110
/// Show a sheet of actions you can take on a message in the message list.
27
111
///
28
112
/// Must have a [MessageListPage] ancestor.
@@ -93,64 +177,6 @@ void showMessageActionSheet({required BuildContext context, required Message mes
93
177
});
94
178
}
95
179
96
- abstract class ActionSheetMenuItemButton extends StatelessWidget {
97
- const ActionSheetMenuItemButton ({super .key, required this .pageContext});
98
-
99
- IconData get icon;
100
- String label (ZulipLocalizations zulipLocalizations);
101
-
102
- /// Called when the button is pressed, after dismissing the action sheet.
103
- ///
104
- /// If the action may take a long time, this method is responsible for
105
- /// arranging any form of progress feedback that may be desired.
106
- ///
107
- /// For operations that need a [BuildContext] , see [pageContext] .
108
- void onPressed ();
109
-
110
- /// A context within the [MessageListPage] this action sheet was
111
- /// triggered from.
112
- final BuildContext pageContext;
113
-
114
- /// The [MessageListPageState] this action sheet was triggered from.
115
- ///
116
- /// Uses the inefficient [BuildContext.findAncestorStateOfType] ;
117
- /// don't call this in a build method.
118
- MessageListPageState findMessageListPage () {
119
- assert (pageContext.mounted,
120
- 'findMessageListPage should be called only when pageContext is known to still be mounted' );
121
- return MessageListPage .ancestorOf (pageContext);
122
- }
123
-
124
- void _handlePressed (BuildContext context) {
125
- // Dismiss the enclosing action sheet immediately,
126
- // for swift UI feedback that the user's selection was received.
127
- Navigator .of (context).pop ();
128
-
129
- assert (pageContext.mounted);
130
- onPressed ();
131
- }
132
-
133
- @override
134
- Widget build (BuildContext context) {
135
- final designVariables = DesignVariables .of (context);
136
- final zulipLocalizations = ZulipLocalizations .of (context);
137
- return MenuItemButton (
138
- trailingIcon: Icon (icon, color: designVariables.contextMenuItemText),
139
- style: MenuItemButton .styleFrom (
140
- padding: const EdgeInsets .symmetric (vertical: 12 , horizontal: 16 ),
141
- foregroundColor: designVariables.contextMenuItemText,
142
- splashFactory: NoSplash .splashFactory,
143
- ).copyWith (backgroundColor: WidgetStateColor .resolveWith ((states) =>
144
- designVariables.contextMenuItemBg.withFadedAlpha (
145
- states.contains (WidgetState .pressed) ? 0.20 : 0.12 ))),
146
- onPressed: () => _handlePressed (context),
147
- child: Text (label (zulipLocalizations),
148
- style: const TextStyle (fontSize: 20 , height: 24 / 20 )
149
- .merge (weightVariableTextStyle (context, wght: 600 )),
150
- ));
151
- }
152
- }
153
-
154
180
abstract class MessageActionSheetMenuItemButton extends ActionSheetMenuItemButton {
155
181
MessageActionSheetMenuItemButton ({
156
182
super .key,
@@ -161,32 +187,6 @@ abstract class MessageActionSheetMenuItemButton extends ActionSheetMenuItemButto
161
187
final Message message;
162
188
}
163
189
164
- class ActionSheetCancelButton extends StatelessWidget {
165
- const ActionSheetCancelButton ({super .key});
166
-
167
- @override
168
- Widget build (BuildContext context) {
169
- final designVariables = DesignVariables .of (context);
170
- return TextButton (
171
- style: TextButton .styleFrom (
172
- padding: const EdgeInsets .all (10 ),
173
- foregroundColor: designVariables.contextMenuCancelText,
174
- shape: RoundedRectangleBorder (borderRadius: BorderRadius .circular (7 )),
175
- splashFactory: NoSplash .splashFactory,
176
- ).copyWith (backgroundColor: WidgetStateColor .fromMap ({
177
- WidgetState .pressed: designVariables.contextMenuCancelPressedBg,
178
- ~ WidgetState .pressed: designVariables.contextMenuCancelBg,
179
- })),
180
- onPressed: () {
181
- Navigator .pop (context);
182
- },
183
- child: Text (ZulipLocalizations .of (context).dialogCancel,
184
- style: const TextStyle (fontSize: 20 , height: 24 / 20 )
185
- .merge (weightVariableTextStyle (context, wght: 600 ))),
186
- );
187
- }
188
- }
189
-
190
190
// This button is very temporary, to complete #125 before we have a way to
191
191
// choose an arbitrary reaction (#388). So, skipping i18n.
192
192
class AddThumbsUpButton extends MessageActionSheetMenuItemButton {
0 commit comments