From 63e840ac1079c115487eef63619187e3eb5871d9 Mon Sep 17 00:00:00 2001 From: Frederik Feichtmeier Date: Fri, 11 Oct 2024 08:21:04 +0200 Subject: [PATCH] fix(YaruSplitButton): normal buttons when no option callback (#930) Ref #912 --- example/lib/pages/split_button_page.dart | 6 ++ lib/src/widgets/yaru_split_button.dart | 81 ++++++++++++------------ 2 files changed, 48 insertions(+), 39 deletions(-) diff --git a/example/lib/pages/split_button_page.dart b/example/lib/pages/split_button_page.dart index abb066f4..3fb7ac5d 100644 --- a/example/lib/pages/split_button_page.dart +++ b/example/lib/pages/split_button_page.dart @@ -77,6 +77,12 @@ class _SplitButtonPageState extends State { menuWidth: width, child: const Text('Main Action'), ), + YaruSplitButton( + menuWidth: width, + child: const Text('Main Action'), + onPressed: () => ScaffoldMessenger.of(context) + .showSnackBar(const SnackBar(content: Text('Main Action'))), + ), ], ), ), diff --git a/lib/src/widgets/yaru_split_button.dart b/lib/src/widgets/yaru_split_button.dart index 1d0cda99..8454ce47 100644 --- a/lib/src/widgets/yaru_split_button.dart +++ b/lib/src/widgets/yaru_split_button.dart @@ -56,13 +56,6 @@ class YaruSplitButton extends StatelessWidget { final defaultRadius = Radius.circular(radius ?? kYaruButtonRadius); - final mainActionShape = RoundedRectangleBorder( - borderRadius: BorderRadius.only( - topLeft: defaultRadius, - bottomLeft: defaultRadius, - ), - ); - final dropdownShape = switch (_variant) { _YaruSplitButtonVariant.outlined => NonUniformRoundedRectangleBorder( hideLeftSide: true, @@ -94,6 +87,15 @@ class YaruSplitButton extends StatelessWidget { ) : null); + final mainActionShape = RoundedRectangleBorder( + borderRadius: onDropdownPressed == null + ? BorderRadius.all(defaultRadius) + : BorderRadius.only( + topLeft: defaultRadius, + bottomLeft: defaultRadius, + ), + ); + final dropdownIcon = icon ?? const Icon(YaruIcons.pan_down); return Row( @@ -116,41 +118,42 @@ class YaruSplitButton extends StatelessWidget { child: child, ), }, - switch (_variant) { - _YaruSplitButtonVariant.elevated => ElevatedButton( - style: ElevatedButton.styleFrom( - fixedSize: size, - minimumSize: size, - maximumSize: size, - padding: dropdownPadding, - shape: dropdownShape, + if (onDropdownPressed != null) + switch (_variant) { + _YaruSplitButtonVariant.elevated => ElevatedButton( + style: ElevatedButton.styleFrom( + fixedSize: size, + minimumSize: size, + maximumSize: size, + padding: dropdownPadding, + shape: dropdownShape, + ), + onPressed: onDropdownPressed, + child: dropdownIcon, ), - onPressed: onDropdownPressed, - child: dropdownIcon, - ), - _YaruSplitButtonVariant.filled => FilledButton( - style: FilledButton.styleFrom( - fixedSize: size, - minimumSize: size, - maximumSize: size, - padding: dropdownPadding, - shape: dropdownShape, + _YaruSplitButtonVariant.filled => FilledButton( + style: FilledButton.styleFrom( + fixedSize: size, + minimumSize: size, + maximumSize: size, + padding: dropdownPadding, + shape: dropdownShape, + ), + onPressed: onDropdownPressed, + child: dropdownIcon, ), - onPressed: onDropdownPressed, - child: dropdownIcon, - ), - _YaruSplitButtonVariant.outlined => OutlinedButton( - style: OutlinedButton.styleFrom( - fixedSize: size, - minimumSize: size, - maximumSize: size, - padding: dropdownPadding, - shape: dropdownShape, + _YaruSplitButtonVariant.outlined => OutlinedButton( + style: OutlinedButton.styleFrom( + fixedSize: size, + minimumSize: size, + maximumSize: size, + padding: dropdownPadding, + shape: dropdownShape, + ), + onPressed: onDropdownPressed, + child: dropdownIcon, ), - onPressed: onDropdownPressed, - child: dropdownIcon, - ), - }, + }, ], ); }