Skip to content

Commit 3e496ec

Browse files
committed
button: Give MenuButton a beforeIcon param, to use for a switch
1 parent 847b326 commit 3e496ec

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

lib/widgets/button.dart

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,12 +288,19 @@ class MenuButton extends StatelessWidget {
288288
required this.label,
289289
required this.onPressed,
290290
this.icon,
291+
this.beforeIcon,
291292
});
292293

293294
final String label;
294295
final VoidCallback onPressed;
295296
final IconData? icon;
296297

298+
/// An element to go before [icon], or in its place if it's null.
299+
///
300+
/// E.g. a switch:
301+
/// https://www.figma.com/design/1JTNtYo9memgW7vV6d0ygq/Zulip-Mobile?node-id=6070-60682&m=dev
302+
final Widget? beforeIcon;
303+
297304
static double itemSpacing = 16;
298305

299306
static bool _debugCheckShapeAncestor(BuildContext context) {
@@ -318,14 +325,21 @@ class MenuButton extends StatelessWidget {
318325
assert(Theme.of(context).visualDensity == VisualDensity.standard);
319326

320327
return MenuItemButton(
321-
trailingIcon: icon != null
328+
trailingIcon: (icon != null || beforeIcon != null)
322329
? Padding(
323330
// This Material widget gives us 12px padding before the icon --
324331
// or more or less, depending on Theme.of(context).visualDensity,
325332
// hence the `assert` above.
326333
padding: EdgeInsetsDirectional.only(start: itemSpacing - 12),
327334

328-
child: Icon(icon, color: designVariables.contextMenuItemText))
335+
child: Row(
336+
mainAxisSize: MainAxisSize.min,
337+
crossAxisAlignment: CrossAxisAlignment.center,
338+
spacing: itemSpacing,
339+
children: [
340+
if (beforeIcon != null) beforeIcon!,
341+
if (icon != null) Icon(icon, color: designVariables.contextMenuItemText),
342+
]))
329343
: null,
330344
style: MenuItemButton.styleFrom(
331345
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),

0 commit comments

Comments
 (0)