diff --git a/forui/lib/src/widgets/button/button.dart b/forui/lib/src/widgets/button/button.dart index ca326a73f..fb6df5044 100644 --- a/forui/lib/src/widgets/button/button.dart +++ b/forui/lib/src/widgets/button/button.dart @@ -27,7 +27,8 @@ class FButton extends StatelessWidget { @useResult static _Data _of(BuildContext context) { final theme = context.dependOnInheritedWidgetOfExactType<_InheritedData>(); - return theme?.data ?? (style: context.theme.buttonStyles.primary, enabled: true); + return theme?.data ?? + (style: context.theme.buttonStyles.primary, enabled: true); } /// The style. Defaults to [FButtonStyle.primary]. @@ -99,6 +100,18 @@ class FButton extends StatelessWidget { label: label, ); + /// Creates a [FButton] that contains only an [icon] + FButton.icon({ + required this.onPress, + required Widget icon, + this.style = Variant.outline, + this.onLongPress, + this.autofocus = false, + this.focusNode, + this.onFocusChange, + super.key, + }) : child = _FButtonIconContent(icon: icon); + /// Creates a [FButton] with custom content. const FButton.raw({ required this.onPress, @@ -129,7 +142,8 @@ class FButton extends StatelessWidget { onPress: onPress, onLongPress: onLongPress, child: DecoratedBox( - decoration: enabled ? style.enabledBoxDecoration : style.disabledBoxDecoration, + decoration: + enabled ? style.enabledBoxDecoration : style.disabledBoxDecoration, child: _InheritedData( data: (style: style, enabled: enabled), child: child, @@ -145,7 +159,8 @@ class FButton extends StatelessWidget { ..add(DiagnosticsProperty('style', style)) ..add(DiagnosticsProperty('onPress', onPress)) ..add(DiagnosticsProperty('onLongPress', onLongPress)) - ..add(FlagProperty('autofocus', value: autofocus, defaultValue: false, ifTrue: 'autofocus')) + ..add(FlagProperty('autofocus', + value: autofocus, defaultValue: false, ifTrue: 'autofocus')) ..add(DiagnosticsProperty('focusNode', focusNode)) ..add(DiagnosticsProperty('onFocusChange', onFocusChange)) ..add(DiagnosticsProperty('builder', child)); @@ -233,7 +248,8 @@ class FButtonCustomStyle extends FButtonStyle with Diagnosticable { }) => FButtonCustomStyle( enabledBoxDecoration: enabledBoxDecoration ?? this.enabledBoxDecoration, - disabledBoxDecoration: disabledBoxDecoration ?? this.disabledBoxDecoration, + disabledBoxDecoration: + disabledBoxDecoration ?? this.disabledBoxDecoration, content: content ?? this.content, icon: icon ?? this.icon, ); @@ -259,7 +275,11 @@ class FButtonCustomStyle extends FButtonStyle with Diagnosticable { icon == other.icon; @override - int get hashCode => enabledBoxDecoration.hashCode ^ disabledBoxDecoration.hashCode ^ content.hashCode ^ icon.hashCode; + int get hashCode => + enabledBoxDecoration.hashCode ^ + disabledBoxDecoration.hashCode ^ + content.hashCode ^ + icon.hashCode; } typedef _Data = ({FButtonCustomStyle style, bool enabled}); diff --git a/forui/lib/src/widgets/button/button_content.dart b/forui/lib/src/widgets/button/button_content.dart index 01be48609..b4475194f 100644 --- a/forui/lib/src/widgets/button/button_content.dart +++ b/forui/lib/src/widgets/button/button_content.dart @@ -18,7 +18,9 @@ final class _FButtonContent extends StatelessWidget { return Padding( padding: style.content.padding, child: DefaultTextStyle.merge( - style: enabled ? style.content.enabledTextStyle : style.content.disabledTextStyle, + style: enabled + ? style.content.enabledTextStyle + : style.content.disabledTextStyle, child: Row( mainAxisAlignment: MainAxisAlignment.center, children: separate( @@ -37,6 +39,22 @@ final class _FButtonContent extends StatelessWidget { } } +final class _FButtonIconContent extends StatelessWidget { + final Widget icon; + + const _FButtonIconContent({required this.icon}); + + @override + Widget build(BuildContext context) { + final (:style, enabled: _) = FButton._of(context); + + return Padding( + padding: style.content.padding, + child: icon, + ); + } +} + /// [FButton] content's style. class FButtonContentStyle with Diagnosticable { /// The [TextStyle] when this button is enabled. @@ -121,5 +139,6 @@ class FButtonContentStyle with Diagnosticable { padding == other.padding; @override - int get hashCode => enabledTextStyle.hashCode ^ disabledTextStyle.hashCode ^ padding.hashCode; + int get hashCode => + enabledTextStyle.hashCode ^ disabledTextStyle.hashCode ^ padding.hashCode; }