Skip to content

Commit

Permalink
fix(YaruSplitButton): normal buttons when no option callback (#930)
Browse files Browse the repository at this point in the history
Ref #912
  • Loading branch information
Feichtmeier authored Oct 11, 2024
1 parent 9bfae97 commit 63e840a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 39 deletions.
6 changes: 6 additions & 0 deletions example/lib/pages/split_button_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ class _SplitButtonPageState extends State<SplitButtonPage> {
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'))),
),
],
),
),
Expand Down
81 changes: 42 additions & 39 deletions lib/src/widgets/yaru_split_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand All @@ -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,
),
},
},
],
);
}
Expand Down

0 comments on commit 63e840a

Please sign in to comment.