Skip to content

Commit

Permalink
allow custom widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
mosberger committed Nov 2, 2023
1 parent 25a52fd commit e2911e5
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 35 deletions.
8 changes: 4 additions & 4 deletions example/lib/pages/button_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ButtonPage extends StatelessWidget {
},
),
const SizedBox(height: sbbDefaultSpacing),
const SBBPrimaryButton(
SBBPrimaryButton(
label: 'Primary Button Disabled',
onPressed: null,
),
Expand Down Expand Up @@ -82,7 +82,7 @@ class ButtonPage extends StatelessWidget {
},
),
const SizedBox(height: sbbDefaultSpacing),
const SBBSecondaryButton(
SBBSecondaryButton(
label: 'Secondary Button Disabled',
onPressed: null,
),
Expand Down Expand Up @@ -111,7 +111,7 @@ class ButtonPage extends StatelessWidget {
},
),
const SizedBox(height: sbbDefaultSpacing),
const SBBTertiaryButtonLarge(
SBBTertiaryButtonLarge(
label: 'Tertiary Button Large Disabled',
onPressed: null,
),
Expand All @@ -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,
Expand Down
15 changes: 8 additions & 7 deletions lib/src/button/sbb_primary_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand All @@ -18,14 +17,16 @@ import 'sbb_button_style_extensions.dart';
/// * <https://digital.sbb.ch/de/design-system-mobile-new/elemente/button>
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;
Expand All @@ -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!),
],
),
);
Expand All @@ -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!),
],
),
);
Expand Down
25 changes: 14 additions & 11 deletions lib/src/button/sbb_secondary_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand All @@ -17,14 +16,16 @@ import 'sbb_button_style_extensions.dart';
/// * <https://digital.sbb.ch/de/design-system-mobile-new/elemente/button>
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;
Expand All @@ -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<SBBButtonStyles>()?.secondaryWebLean : Theme.of(context).outlinedButtonTheme.style?.copyWith(
// workaround for web
padding: SBBTheme.allStates(EdgeInsets.zero),
),
style: isWeb
? Theme.of(context).extension<SBBButtonStyles>()?.secondaryWebLean
: Theme.of(context).outlinedButtonTheme.style?.copyWith(
// workaround for web
padding: SBBTheme.allStates(EdgeInsets.zero),
),
onPressed: isLoading ? null : onPressed,
focusNode: focusNode,
child: Padding(
Expand All @@ -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!),
],
),
),
Expand Down Expand Up @@ -85,4 +88,4 @@ class SBBGhostButton extends StatelessWidget {
),
);
}
}
}
28 changes: 15 additions & 13 deletions lib/src/button/sbb_tertiary_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ import '../sbb_internal.dart';
/// * <https://digital.sbb.ch/de/design-system-mobile-new/elemente/button>
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;
Expand All @@ -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!),
],
),
),
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit e2911e5

Please sign in to comment.