Skip to content

Commit cc8c022

Browse files
committed
button: Give MenuButton an optional toggle param
1 parent 10c647f commit cc8c022

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

lib/widgets/button.dart

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -289,12 +289,19 @@ class MenuButton extends StatelessWidget {
289289
required this.label,
290290
required this.onPressed,
291291
this.icon,
292+
this.toggle,
292293
});
293294

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

299+
/// A [Toggle] to go before [icon], or in its place if it's null.
300+
///
301+
/// See Figma:
302+
/// https://www.figma.com/design/1JTNtYo9memgW7vV6d0ygq/Zulip-Mobile?node-id=6070-60682&m=dev
303+
final Widget? toggle;
304+
298305
static double itemSpacing = 16;
299306

300307
static bool _debugCheckShapeAncestor(BuildContext context) {
@@ -319,26 +326,37 @@ class MenuButton extends StatelessWidget {
319326
assert(Theme.of(context).visualDensity == VisualDensity.standard);
320327

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

329-
child: Icon(icon, color: designVariables.contextMenuItemText))
336+
child: Row(
337+
mainAxisSize: MainAxisSize.min,
338+
crossAxisAlignment: CrossAxisAlignment.center,
339+
spacing: itemSpacing,
340+
children: [
341+
if (toggle != null) toggle!,
342+
if (icon != null) Icon(icon!, color: designVariables.contextMenuItemText),
343+
]))
330344
: null,
331345
style: MenuItemButton.styleFrom(
332-
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
346+
minimumSize: Size.fromHeight(48),
347+
padding: const EdgeInsets.symmetric(horizontal: 16),
333348
foregroundColor: designVariables.contextMenuItemText,
334349
splashFactory: NoSplash.splashFactory,
335350
).copyWith(backgroundColor: WidgetStateColor.resolveWith((states) =>
336351
designVariables.contextMenuItemBg.withFadedAlpha(
337352
states.contains(WidgetState.pressed) ? 0.20 : 0.12))),
338353
onPressed: onPressed,
339-
child: Text(label,
340-
style: const TextStyle(fontSize: 20, height: 24 / 20)
341-
.merge(weightVariableTextStyle(context, wght: 600))));
354+
child: Padding(
355+
padding: const EdgeInsets.symmetric(vertical: 4),
356+
child: Text(label,
357+
style: const TextStyle(fontSize: 20, height: 24 / 20)
358+
.merge(weightVariableTextStyle(context, wght: 600))),
359+
));
342360
}
343361
}
344362

0 commit comments

Comments
 (0)