From e2911e5bb5eb11f5c69918007cf033b5abb3af38 Mon Sep 17 00:00:00 2001 From: Dominik Mosberger <9129636+mosberger@users.noreply.github.com> Date: Thu, 2 Nov 2023 13:24:03 +0100 Subject: [PATCH] allow custom widgets --- example/lib/pages/button_page.dart | 8 +++---- lib/src/button/sbb_primary_button.dart | 15 +++++++------ lib/src/button/sbb_secondary_button.dart | 25 +++++++++++---------- lib/src/button/sbb_tertiary_button.dart | 28 +++++++++++++----------- 4 files changed, 41 insertions(+), 35 deletions(-) diff --git a/example/lib/pages/button_page.dart b/example/lib/pages/button_page.dart index ba6faecf..c544ec63 100644 --- a/example/lib/pages/button_page.dart +++ b/example/lib/pages/button_page.dart @@ -27,7 +27,7 @@ class ButtonPage extends StatelessWidget { }, ), const SizedBox(height: sbbDefaultSpacing), - const SBBPrimaryButton( + SBBPrimaryButton( label: 'Primary Button Disabled', onPressed: null, ), @@ -82,7 +82,7 @@ class ButtonPage extends StatelessWidget { }, ), const SizedBox(height: sbbDefaultSpacing), - const SBBSecondaryButton( + SBBSecondaryButton( label: 'Secondary Button Disabled', onPressed: null, ), @@ -111,7 +111,7 @@ class ButtonPage extends StatelessWidget { }, ), const SizedBox(height: sbbDefaultSpacing), - const SBBTertiaryButtonLarge( + SBBTertiaryButtonLarge( label: 'Tertiary Button Large Disabled', onPressed: null, ), @@ -130,7 +130,7 @@ class ButtonPage extends StatelessWidget { }, ), const SizedBox(height: sbbDefaultSpacing), - const SBBTertiaryButtonLarge( + SBBTertiaryButtonLarge( label: 'Tertiary Button Large Icon Disabled', icon: SBBIcons.plus_small, onPressed: null, diff --git a/lib/src/button/sbb_primary_button.dart b/lib/src/button/sbb_primary_button.dart index 1e3bd0e8..f8bd5c63 100644 --- a/lib/src/button/sbb_primary_button.dart +++ b/lib/src/button/sbb_primary_button.dart @@ -2,7 +2,6 @@ import 'package:flutter/material.dart'; import '../../design_system_flutter.dart'; import '../sbb_internal.dart'; -import 'sbb_button_style_extensions.dart'; /// The SBB Primary Button. Use according to documentation. /// @@ -18,14 +17,16 @@ import 'sbb_button_style_extensions.dart'; /// * class SBBPrimaryButton extends StatelessWidget { const SBBPrimaryButton({ - Key? key, - required this.label, + super.key, + this.label, + this.child, this.isLoading = false, required this.onPressed, this.focusNode, - }) : super(key: key); + }) : assert(label != null && child == null || label == null && child != null); - final String label; + final String? label; + final Widget? child; final bool isLoading; final VoidCallback? onPressed; final FocusNode? focusNode; @@ -51,7 +52,7 @@ class SBBPrimaryButton extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.center, children: [ if (isLoading) SBBLoadingIndicator.tinyCloud(), - SBBButtonContent(label: label) + if (label == null) child! else SBBButtonContent(label: label!), ], ), ); @@ -65,7 +66,7 @@ class SBBPrimaryButton extends StatelessWidget { child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - SBBButtonContent(label: label) + if (label == null) child! else SBBButtonContent(label: label!), ], ), ); diff --git a/lib/src/button/sbb_secondary_button.dart b/lib/src/button/sbb_secondary_button.dart index dd5011aa..2727978b 100644 --- a/lib/src/button/sbb_secondary_button.dart +++ b/lib/src/button/sbb_secondary_button.dart @@ -2,7 +2,6 @@ import 'package:flutter/material.dart'; import '../../design_system_flutter.dart'; import '../sbb_internal.dart'; -import 'sbb_button_style_extensions.dart'; /// The SBB Secondary Button. Use according to documentation. /// @@ -17,14 +16,16 @@ import 'sbb_button_style_extensions.dart'; /// * class SBBSecondaryButton extends StatelessWidget { const SBBSecondaryButton({ - Key? key, - required this.label, + super. key, + this.label, + this.child, this.isLoading = false, required this.onPressed, this.focusNode, - }) : super(key: key); + }) : assert(label != null && child == null || label == null && child != null); - final String label; + final String? label; + final Widget? child; final bool isLoading; final VoidCallback? onPressed; final FocusNode? focusNode; @@ -34,10 +35,12 @@ class SBBSecondaryButton extends StatelessWidget { final isWeb = SBBBaseStyle.of(context).hostPlatform == HostPlatform.web; final style = SBBBaseStyle.of(context); return OutlinedButton( - style: isWeb ? Theme.of(context).extension()?.secondaryWebLean : Theme.of(context).outlinedButtonTheme.style?.copyWith( - // workaround for web - padding: SBBTheme.allStates(EdgeInsets.zero), - ), + style: isWeb + ? Theme.of(context).extension()?.secondaryWebLean + : Theme.of(context).outlinedButtonTheme.style?.copyWith( + // workaround for web + padding: SBBTheme.allStates(EdgeInsets.zero), + ), onPressed: isLoading ? null : onPressed, focusNode: focusNode, child: Padding( @@ -51,7 +54,7 @@ class SBBSecondaryButton extends StatelessWidget { const SBBLoadingIndicator.tinySmoke(), const SBBLoadingIndicator.tinyCement(), ), - SBBButtonContent(label: label) + if (label == null) child! else SBBButtonContent(label: label!), ], ), ), @@ -85,4 +88,4 @@ class SBBGhostButton extends StatelessWidget { ), ); } -} \ No newline at end of file +} diff --git a/lib/src/button/sbb_tertiary_button.dart b/lib/src/button/sbb_tertiary_button.dart index 79d02e31..f18cc7f1 100644 --- a/lib/src/button/sbb_tertiary_button.dart +++ b/lib/src/button/sbb_tertiary_button.dart @@ -16,15 +16,17 @@ import '../sbb_internal.dart'; /// * class SBBTertiaryButtonLarge extends StatelessWidget { const SBBTertiaryButtonLarge({ - Key? key, - required this.label, + super.key, + this.label, + this.child, this.icon, this.isLoading = false, required this.onPressed, this.focusNode, - }) : super(key: key); + }) : assert(label != null && child == null || label == null && child != null); - final String label; + final String? label; + final Widget? child; final IconData? icon; final bool isLoading; final VoidCallback? onPressed; @@ -47,19 +49,16 @@ class SBBTertiaryButtonLarge extends StatelessWidget { mainAxisSize: MainAxisSize.min, children: [ if (isLoading) - style.themeValue(const SBBLoadingIndicator.tinySmoke(), const SBBLoadingIndicator.tinyCement()) + style.themeValue( + const SBBLoadingIndicator.tinySmoke(), + const SBBLoadingIndicator.tinyCement(), + ) else if (icon != null) Padding( padding: const EdgeInsetsDirectional.only(end: 4.0), child: Icon(icon, size: sbbIconSizeSmall), ), - Flexible( - child: Text( - label, - overflow: TextOverflow.ellipsis, - maxLines: 1, - ), - ), + if (label == null) child! else SBBButtonContent(label: label!), ], ), ), @@ -116,7 +115,10 @@ class SBBTertiaryButtonSmall extends StatelessWidget { mainAxisSize: MainAxisSize.min, children: [ if (isLoading) - style.themeValue(const SBBLoadingIndicator.tinyCement(), const SBBLoadingIndicator.tinySmoke()) + style.themeValue( + const SBBLoadingIndicator.tinyCement(), + const SBBLoadingIndicator.tinySmoke(), + ) else if (icon != null) Padding( padding: const EdgeInsetsDirectional.only(end: 4.0),