Skip to content

Commit

Permalink
cleanup warnings, fix issue with button label builder
Browse files Browse the repository at this point in the history
  • Loading branch information
mosberger committed Nov 29, 2023
1 parent 25a1fba commit c9699ca
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 67 deletions.
2 changes: 1 addition & 1 deletion example/lib/web_pages/accordion_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class _AccordionPageState extends State<AccordionPage> {
'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.',
),
];
int _expandedIndex = -1;

@override
Widget build(BuildContext context) {
return SizedBox.expand(
Expand Down
3 changes: 0 additions & 3 deletions example/lib/web_pages/breadcrumb_page.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import 'dart:ui';

import 'package:design_system_flutter/design_system_flutter.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';

List<Widget> _levels = [
Expand Down
1 change: 0 additions & 1 deletion lib/src/accordion/sbb_accordion.dart
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ class _SBBAccordionState extends State<SBBAccordion> {
}

Widget _buildAccordionWeb(BuildContext context, SBBAccordionItem child, int i) {
final style = SBBControlStyles.of(context);
return Container(
decoration: BoxDecoration(
color: widget.backgroundColor ??
Expand Down
12 changes: 9 additions & 3 deletions lib/src/button/sbb_icon_text_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import '../../design_system_flutter.dart';
/// See also:
///
/// * <https://digital.sbb.ch/de/design-system-mobile-new/elemente/button>
@Deprecated('IconTextButton is not part of the design system and will be removed.')
class SBBIconTextButton extends StatefulWidget {
const SBBIconTextButton({
Key? key,
Expand Down Expand Up @@ -89,10 +90,15 @@ class _SBBIconTextButtonState extends State<SBBIconTextButton> {
: style?.iconColorDisabled,
),
const SizedBox(height: 4.0),
buttonStyle.buttonLabelBuilder(
context,
Text(
widget.label,
style: textStyle,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: _isPressed || _hasFocus
? style?.textStyleHighlighted
: isEnabled
? style?.textStyle
: style?.textStyleDisabled,
),
],
),
Expand Down
9 changes: 4 additions & 5 deletions lib/src/button/sbb_primary_button.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:flutter/material.dart';

import '../../design_system_flutter.dart';
import '../sbb_internal.dart';

/// The SBB Primary Button. Use according to documentation.
///
Expand Down Expand Up @@ -51,7 +50,7 @@ class SBBPrimaryButton extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.center,
children: [
if (isLoading) SBBLoadingIndicator.tinyCloud(),
styles.buttonLabelBuilder(context, label),
styles.buttonLabelBuilder!(context, label),
],
),
);
Expand All @@ -66,7 +65,7 @@ class SBBPrimaryButton extends StatelessWidget {
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
styles.buttonLabelBuilder(context, label),
styles.buttonLabelBuilder!(context, label),
],
),
);
Expand Down Expand Up @@ -121,7 +120,7 @@ class SBBPrimaryButtonNegative extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.center,
children: [
if (isLoading) SBBLoadingIndicator.tinyCloud(),
styles.buttonLabelBuilder(context, label),
styles.buttonLabelBuilder!(context, label),
],
),
);
Expand All @@ -136,7 +135,7 @@ class SBBPrimaryButtonNegative extends StatelessWidget {
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
styles.buttonLabelBuilder(context, label),
styles.buttonLabelBuilder!(context, label),
],
),
);
Expand Down
5 changes: 2 additions & 3 deletions lib/src/button/sbb_secondary_button.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:flutter/material.dart';

import '../../design_system_flutter.dart';
import '../sbb_internal.dart';

/// The SBB Secondary Button. Use according to documentation.
///
Expand Down Expand Up @@ -53,7 +52,7 @@ class SBBSecondaryButton extends StatelessWidget {
const SBBLoadingIndicator.tinySmoke(),
const SBBLoadingIndicator.tinyCement(),
),
buttonStyles.buttonLabelBuilder(context, label),
buttonStyles.buttonLabelBuilder!(context, label),
],
),
),
Expand Down Expand Up @@ -85,7 +84,7 @@ class SBBGhostButton extends StatelessWidget {
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
styles.buttonLabelBuilder(context, label),
styles.buttonLabelBuilder!(context, label),
],
),
);
Expand Down
4 changes: 2 additions & 2 deletions lib/src/button/sbb_tertiary_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class SBBTertiaryButtonLarge extends StatelessWidget {
padding: const EdgeInsetsDirectional.only(end: 4.0),
child: Icon(icon, size: sbbIconSizeSmall),
),
buttonStyles.buttonLabelBuilder(context, label),
buttonStyles.buttonLabelBuilder!(context, label),
],
),
),
Expand Down Expand Up @@ -123,7 +123,7 @@ class SBBTertiaryButtonSmall extends StatelessWidget {
padding: const EdgeInsetsDirectional.only(end: 4.0),
child: Icon(icon, size: sbbIconSizeSmall),
),
buttonStyle.buttonLabelBuilder(context, label),
buttonStyle.buttonLabelBuilder!(context, label),
],
),
),
Expand Down
25 changes: 5 additions & 20 deletions lib/src/dropdown/sbb_dropdown.dart
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,7 @@ class _DropdownRoute<T> extends PopupRoute<_DropdownRouteResult<T>> {
this.menuMaxHeight,
required this.enableFeedback,
this.borderRadius,
}) : assert(style != null),
itemHeights =
}) : itemHeights =
List<double>.filled(items.length, itemHeight ?? _kMenuItemHeight);

final List<_MenuItem<T>> items;
Expand Down Expand Up @@ -586,8 +585,7 @@ class _MenuItem<T> extends SingleChildRenderObjectWidget {
Key? key,
required this.onLayout,
required this.item,
}) : assert(onLayout != null),
super(key: key, child: item);
}) : super(key: key, child: item);

final ValueChanged<Size> onLayout;
final SBBDropdownMenuItem<T>? item;
Expand All @@ -606,8 +604,7 @@ class _MenuItem<T> extends SingleChildRenderObjectWidget {

class _RenderMenuItem extends RenderProxyBox {
_RenderMenuItem(this.onLayout, [RenderBox? child])
: assert(onLayout != null),
super(child);
: super(child);

ValueChanged<Size> onLayout;

Expand All @@ -629,8 +626,7 @@ class _DropdownMenuItemContainer extends StatelessWidget {
Key? key,
this.alignment = AlignmentDirectional.centerStart,
required this.child,
}) : assert(child != null),
super(key: key);
}) : super(key: key);

/// The widget below this widget in the tree.
///
Expand Down Expand Up @@ -674,8 +670,7 @@ class SBBDropdownMenuItem<T> extends _DropdownMenuItemContainer {
this.enabled = true,
AlignmentGeometry alignment = AlignmentDirectional.centerStart,
required Widget child,
}) : assert(child != null),
super(key: key, alignment: alignment, child: child);
}) : super(key: key, alignment: alignment, child: child);

/// Called when the dropdown menu item is tapped.
final VoidCallback? onTap;
Expand Down Expand Up @@ -800,11 +795,6 @@ class SBBDropdownButton<T> extends StatefulWidget {
'Either zero or 2 or more [DropdownMenuItem]s were detected '
'with the same value',
),
assert(elevation != null),
assert(iconSize != null),
assert(isDense != null),
assert(isExpanded != null),
assert(autofocus != null),
super(key: key);

/// The list of items the user can select.
Expand Down Expand Up @@ -1445,11 +1435,6 @@ class SBBDropdownButtonFormField<T> extends FormField<T> {
'Either zero or 2 or more [DropdownMenuItem]s were detected '
'with the same value',
),
assert(elevation != null),
assert(iconSize != null),
assert(isDense != null),
assert(isExpanded != null),
assert(autofocus != null),
decoration = decoration ?? InputDecoration(focusColor: focusColor),
super(
key: key,
Expand Down
3 changes: 0 additions & 3 deletions lib/src/link/sbb_link_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,9 @@ class _SBBLinkTextState extends State<SBBLinkText> {

List<TextSpan> _textSpans() {
final style = SBBBaseStyle.of(context);
final controlStyle = SBBControlStyles.of(context);
bool isWeb = SBBBaseStyle.of(context).hostPlatform == HostPlatform.web;
final hasCustomStyle = widget.style != null;
final textStyle = hasCustomStyle ? widget.style!.copyWith(color: widget.style!.color ?? style.defaultTextStyle!.color) : style.defaultTextStyle;
final linkStyle = hasCustomStyle ? textStyle!.copyWith(color: controlStyle.linkTextStyle!.color) : controlStyle.linkTextStyle;
final linkStylePressed = hasCustomStyle ? textStyle!.copyWith(color: controlStyle.linkTextStyleHighlighted!.color) : controlStyle.linkTextStyleHighlighted;

final texts = widget.text.split(_regExpMarkDownLink);
final links = _regExpMarkDownLink.allMatches(widget.text).toList();
Expand Down
4 changes: 1 addition & 3 deletions lib/src/sbb_internal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ class SBBInternal {
}

class SBBButtonContent extends StatelessWidget {
const SBBButtonContent({Key? key, required this.label, this.style})
const SBBButtonContent({Key? key, required this.label})
: super(key: key);

final String label;
final TextStyle? style;

@override
Widget build(BuildContext context) {
Expand All @@ -54,7 +53,6 @@ class SBBButtonContent extends StatelessWidget {
label,
overflow: TextOverflow.ellipsis,
maxLines: 1,
style: style,
),
);
}
Expand Down
7 changes: 2 additions & 5 deletions lib/src/text/sbb_autocompletion.dart
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,6 @@ class SBBAutocompletionState<T> extends State<SBBAutocompletion<T>>
}

void _updateWebOverlay({String? query, bool metricsChanged = false}) {
final bool isWeb =
SBBBaseStyle.of(context).hostPlatform == HostPlatform.web;

filteredSuggestions = getSuggestions(
widget.suggestions,
widget.itemSorter,
Expand Down Expand Up @@ -378,7 +375,7 @@ class SBBAutocompletionState<T> extends State<SBBAutocompletion<T>>
);

if (listSuggestionsEntry != null) {
Overlay.of(context)?.insert(listSuggestionsEntry!);
Overlay.of(context).insert(listSuggestionsEntry!);
}
} else {
if (listSuggestionsEntry != null) {
Expand Down Expand Up @@ -524,7 +521,7 @@ class SBBAutocompletionState<T> extends State<SBBAutocompletion<T>>
);

if (listSuggestionsEntry != null) {
Overlay.of(context)?.insert(listSuggestionsEntry!);
Overlay.of(context).insert(listSuggestionsEntry!);
}
}
} else {
Expand Down
21 changes: 7 additions & 14 deletions lib/src/theme/styles/src/sbb_button_styles.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ import 'package:flutter/material.dart';
import '../../../sbb_internal.dart';
import '../sbb_styles.dart';

typedef ButtonLabelBuilder = Widget Function(
BuildContext context,
String label, {
TextStyle? style,
});
typedef ButtonLabelBuilder = Widget Function(BuildContext context, String label);

class SBBButtonStyles extends ThemeExtension<SBBButtonStyles> {
SBBButtonStyles({
Expand All @@ -23,7 +19,7 @@ class SBBButtonStyles extends ThemeExtension<SBBButtonStyles> {
this.iconSmallBorderlessStyle,
this.iconFormStyle,
this.iconTextStyle,
required this.buttonLabelBuilder,
this.buttonLabelBuilder,
});

factory SBBButtonStyles.$default({required SBBBaseStyle baseStyle}) => SBBButtonStyles(
Expand Down Expand Up @@ -164,9 +160,8 @@ class SBBButtonStyles extends ThemeExtension<SBBButtonStyles> {
buttonLabelBuilder: defaultButtonLabelBuilder,
);

static ButtonLabelBuilder defaultButtonLabelBuilder = (_, String label, { TextStyle? style }) {
return SBBButtonContent(label: label, style: style);
};
static ButtonLabelBuilder defaultButtonLabelBuilder =
(_, String label) => SBBButtonContent(label: label);

final SBBButtonStyle? primaryStyle;
final SBBButtonStyle? primaryNegativeStyle;
Expand All @@ -180,7 +175,7 @@ class SBBButtonStyles extends ThemeExtension<SBBButtonStyles> {
final SBBButtonStyle? iconSmallBorderlessStyle;
final SBBButtonStyle? iconFormStyle;
final SBBButtonStyle? iconTextStyle;
final ButtonLabelBuilder buttonLabelBuilder;
final ButtonLabelBuilder? buttonLabelBuilder;

static SBBButtonStyles of(BuildContext context) => Theme.of(context).extension<SBBButtonStyles>()!;

Expand Down Expand Up @@ -265,9 +260,7 @@ class SBBButtonStyles extends ThemeExtension<SBBButtonStyles> {

extension ButtonStylesExtension on SBBButtonStyles? {
SBBButtonStyles merge(SBBButtonStyles? other) {
if (this == null) return other ?? SBBButtonStyles(
buttonLabelBuilder: SBBButtonStyles.defaultButtonLabelBuilder,
);
if (this == null) return other ?? SBBButtonStyles();
return this!.copyWith(
primaryStyle: this!.primaryStyle.merge(other?.primaryStyle),
primaryNegativeStyle: this!.primaryNegativeStyle.merge(other?.primaryNegativeStyle),
Expand All @@ -281,7 +274,7 @@ extension ButtonStylesExtension on SBBButtonStyles? {
iconSmallBorderlessStyle: this!.iconSmallBorderlessStyle.merge(other?.iconSmallBorderlessStyle),
iconFormStyle: this!.iconFormStyle.merge(other?.iconFormStyle),
iconTextStyle: this!.iconTextStyle.merge(other?.iconTextStyle),
buttonLabelBuilder: other?.buttonLabelBuilder ?? this!.buttonLabelBuilder,
buttonLabelBuilder: this!.buttonLabelBuilder ?? other?.buttonLabelBuilder,
) as SBBButtonStyles;
}
}
2 changes: 1 addition & 1 deletion lib/src/toast/sbb_toast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class SBBToast {
Timer? _removeTimer;

static SBBToast of(BuildContext context) {
return SBBToast._(Overlay.of(context, rootOverlay: true)!);
return SBBToast._(Overlay.of(context, rootOverlay: true));
}

void confirmation({
Expand Down
3 changes: 0 additions & 3 deletions test/sbb_tab_bar_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,4 @@ class _DemoItem extends TabBarItem {

@override
String translate(BuildContext context) => 'Item $id';

@override
String translateSemantics(BuildContext context, int index, int length) => 'Element $index von $length';
}

0 comments on commit c9699ca

Please sign in to comment.