Skip to content

Commit

Permalink
remove golden_toolkit, fix golden tests (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
mosberger authored May 24, 2024
1 parent 7908df3 commit 32eb657
Show file tree
Hide file tree
Showing 105 changed files with 814 additions and 751 deletions.
6 changes: 2 additions & 4 deletions example/lib/pages/onboarding_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ class _OnboardingPage extends StatelessWidget {
final builderDelegate = DemoOnboardingBuilderDelegate();
return Scaffold(
appBar: _PreferredSizeWidget(),
body: WillPopScope(
onWillPop: () {
return builderDelegate.onPop();
},
body: PopScope(
onPopInvoked: (didPop) => builderDelegate.onPop(),
child: SBBOnboarding(
builderDelegate: builderDelegate,
onFinish: () => Navigator.of(context).pop(),
Expand Down
2 changes: 1 addition & 1 deletion example/lib/web_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class _SidePanelPageState extends State<_SidePanelPage> {
}

final SBBUserMenu _exampleUserMenu = SBBUserMenu(
displayName: "Eisen Bahner",
displayName: 'Eisen Bahner',
itemBuilder: (BuildContext context) => <SBBMenuEntry>[
SBBMenuItem.tile(
icon: SBBIcons.user_medium,
Expand Down
20 changes: 10 additions & 10 deletions example/lib/web_pages/status_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,35 +44,35 @@ class StatusPage extends StatelessWidget {
SBBWebText.headerThree('- Text'),
SBBStatus.valid(
showIcon: false,
text: "Success",
text: 'Success',
),
SizedBox(
height: 10,
),
SBBStatus.warning(
showIcon: false,
text: "Warning",
text: 'Warning',
),
SizedBox(
height: 10,
),
SBBStatus.invalid(
showIcon: false,
text: "Failure",
text: 'Failure',
),
SizedBox(
height: 10,
),
SBBStatus.inProgress(
showIcon: false,
text: "In Progress",
text: 'In Progress',
),
SizedBox(
height: 10,
),
SBBStatus.inactive(
showIcon: false,
text: "Offline",
text: 'Offline',
),
SizedBox(
height: 20,
Expand All @@ -83,31 +83,31 @@ class StatusPage extends StatelessWidget {
),
SBBWebText.headerThree('- Extended'),
SBBStatus.valid(
text: "Everything is valid",
text: 'Everything is valid',
),
SizedBox(
height: 10,
),
SBBStatus.warning(
text: "There is a potential problem",
text: 'There is a potential problem',
),
SizedBox(
height: 10,
),
SBBStatus.invalid(
text: "Somethign needs to be corrected",
text: 'Somethign needs to be corrected',
),
SizedBox(
height: 10,
),
SBBStatus.inProgress(
text: "Process is in progress",
text: 'Process is in progress',
),
SizedBox(
height: 10,
),
SBBStatus.inactive(
text: "Application is offline",
text: 'Application is offline',
),
SizedBox(
height: 20,
Expand Down
16 changes: 8 additions & 8 deletions lib/src/breadcrumb/sbb_breadcrumb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SBBBreadcrumb extends StatelessWidget {
/// The color for Text and Icons descendants below [SBBBreadcrumb].
///
/// Defaults to [SBBTheme.breadcrumbForegroundColor].
final MaterialStateProperty<Color?>? foregroundColor;
final WidgetStateProperty<Color?>? foregroundColor;

/// The text style for text descendants below [SBBBreadcrumb].
///
Expand Down Expand Up @@ -96,7 +96,7 @@ class _InheritedBreadcrumbStyle extends InheritedWidget {
required Widget child,
}) : super(key: key, child: child);

final MaterialStateProperty<Color?> foregroundColor;
final WidgetStateProperty<Color?> foregroundColor;
final TextStyle textStyle;

static _InheritedBreadcrumbStyle of(BuildContext context) {
Expand Down Expand Up @@ -150,7 +150,7 @@ class _SBBBreadcrumbItemState extends State<SBBBreadcrumbItem>
return InkWell(
onTap: () {
if (widget._enabled) {
updateMaterialState(MaterialState.pressed);
updateMaterialState(WidgetState.pressed);
widget.onPressed!();
}
},
Expand All @@ -159,7 +159,7 @@ class _SBBBreadcrumbItemState extends State<SBBBreadcrumbItem>
highlightColor: SBBColors.transparent,
mouseCursor: _getEffectiveMouseCursor(),
onHover:
widget._enabled ? updateMaterialState(MaterialState.hovered) : null,
widget._enabled ? updateMaterialState(WidgetState.hovered) : null,
child: DefaultTextStyle(
style: resolvedTextStyle.copyWith(color: resolvedForegroundColor),
child: IconTheme.merge(
Expand All @@ -171,10 +171,10 @@ class _SBBBreadcrumbItemState extends State<SBBBreadcrumbItem>
}

MouseCursor _getEffectiveMouseCursor() =>
MaterialStateProperty.resolveAs<MouseCursor>(
MaterialStateMouseCursor.clickable,
<MaterialState>{
if (!widget._enabled) MaterialState.disabled,
WidgetStateProperty.resolveAs<MouseCursor>(
WidgetStateMouseCursor.clickable,
<WidgetState>{
if (!widget._enabled) WidgetState.disabled,
},
);
}
2 changes: 1 addition & 1 deletion lib/src/button/sbb_button_style_extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ extension SBBButtonStylesExtension on SBBButtonStyles {
padding: SBBTheme.allStates(EdgeInsets.symmetric(horizontal: sbbDefaultSpacing)),
elevation: SBBTheme.allStates(0),
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
mouseCursor: MaterialStateMouseCursor.clickable,
mouseCursor: WidgetStateMouseCursor.clickable,
);

ButtonStyle get primaryMobile => primaryStyle!.overrideButtonStyle(_baseButtonStyle);
Expand Down
20 changes: 10 additions & 10 deletions lib/src/dropdown/sbb_dropdown.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// found in the LICENSE file.

import 'dart:math' as math;
import 'dart:ui' show window;

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -84,7 +83,7 @@ class _DropdownMenuItemButtonState<T> extends State<_DropdownMenuItemButton<T>>
widget.route.items[widget.itemIndex].item!;

//TODO: solve with material state
final MaterialStateProperty<Color?> leftBorderColor =
final WidgetStateProperty<Color?> leftBorderColor =
SBBTheme.resolveStatesWith(
defaultValue: SBBColors.transparent, hoveredValue: SBBColors.red);

Expand All @@ -104,7 +103,7 @@ class _DropdownMenuItemButtonState<T> extends State<_DropdownMenuItemButton<T>>
autofocus: widget.itemIndex == widget.route.selectedIndex,
enableFeedback: widget.enableFeedback,
onTap: _handleOnTap,
onHover: updateMaterialState(MaterialState.hovered),
onHover: updateMaterialState(WidgetState.hovered),
borderRadius: _forLastItemOnly(),
child: child,
);
Expand Down Expand Up @@ -1213,7 +1212,7 @@ class _SBBDropdownButtonState<T> extends State<SBBDropdownButton<T>>
if (result == null) {
// If there's no MediaQuery, then use the window aspect to determine
// orientation.
final Size size = window.physicalSize;
final Size size = View.of(context).physicalSize;
result = size.width > size.height
? Orientation.landscape
: Orientation.portrait;
Expand Down Expand Up @@ -1261,8 +1260,9 @@ class _SBBDropdownButtonState<T> extends State<SBBDropdownButton<T>>
items.add(DefaultTextStyle(
style: _textStyle!.copyWith(color: _hintColor),
child: IgnorePointer(
ignoringSemantics: false,
child: displayedHint,
child: ExcludeSemantics(
child: displayedHint,
),
),
));
}
Expand Down Expand Up @@ -1340,10 +1340,10 @@ class _SBBDropdownButtonState<T> extends State<SBBDropdownButton<T>>
);

final MouseCursor effectiveMouseCursor =
MaterialStateProperty.resolveAs<MouseCursor>(
MaterialStateMouseCursor.clickable,
<MaterialState>{
if (!_enabled) MaterialState.disabled,
WidgetStateProperty.resolveAs<MouseCursor>(
WidgetStateMouseCursor.clickable,
<WidgetState>{
if (!_enabled) WidgetState.disabled,
},
);

Expand Down
4 changes: 2 additions & 2 deletions lib/src/header/sbb_web_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class _SBBWebHeaderNavItemState extends State<SBBWebHeaderNavItem>
@override
Widget build(BuildContext context) {
final style = SBBControlStyles.of(context).headerNavItemForegroundColor;
if (widget.selected!) setMaterialState(MaterialState.pressed, true);
if (widget.selected!) setMaterialState(WidgetState.pressed, true);
return Semantics(
link: true,
onTap: widget.onTap,
Expand All @@ -155,7 +155,7 @@ class _SBBWebHeaderNavItemState extends State<SBBWebHeaderNavItem>
onTap: widget.onTap,
onHover: widget.selected!
? null
: updateMaterialState(MaterialState.hovered),
: updateMaterialState(WidgetState.hovered),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Text(widget.title))),
Expand Down
7 changes: 3 additions & 4 deletions lib/src/logo/sbb_logo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@ class SBBLogo extends StatelessWidget {
///
/// respects parent's size and scales accordingly
class SBBWebLogo extends StatelessWidget {
static const _defaultHeight = 20.0;
static const _defaultWidth = 59.0;
static const _defaultAspectRatio = _defaultWidth / _defaultHeight;

const SBBWebLogo({
Key? key,
this.height,
Expand All @@ -106,6 +102,9 @@ class SBBWebLogo extends StatelessWidget {
this.backgroundColor = SBBColors.red,
this.borderColor,
}) : super(key: key);
static const _defaultHeight = 20.0;
static const _defaultWidth = 59.0;
static const _defaultAspectRatio = _defaultWidth / _defaultHeight;

final double? height;
final double? width;
Expand Down
24 changes: 12 additions & 12 deletions lib/src/menu/sbb_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ class SBBMenuItem<T> extends SBBMenuEntry<T> {
double height,
EdgeInsets padding,
TextStyle? textStyle,
MaterialStateProperty<Color?>? foregroundColor,
MaterialStateProperty<Color?>? backgroundColor,
WidgetStateProperty<Color?>? foregroundColor,
WidgetStateProperty<Color?>? backgroundColor,
IconData? icon,
required String title,
}) = _SBBMenuTileItem;
Expand Down Expand Up @@ -275,10 +275,10 @@ class SBBMenuItem<T> extends SBBMenuEntry<T> {
/// The color for the tile's [Text] and [Icon] widget descendants.
///
/// This color is typically used instead of the color of the [textStyle].
final MaterialStateProperty<Color?>? foregroundColor;
final WidgetStateProperty<Color?>? foregroundColor;

/// The color for the tile's background.
final MaterialStateProperty<Color?>? backgroundColor;
final WidgetStateProperty<Color?>? backgroundColor;

@override
bool represents(T? value) => value == this.value;
Expand Down Expand Up @@ -309,7 +309,7 @@ class SBBMenuItemState<T, W extends SBBMenuItem<T>> extends State<W>
@protected
void handleTap() {
updateMaterialState(
MaterialState.pressed,
WidgetState.pressed,
);
widget.onTap?.call();
Navigator.pop<T>(context, widget.value);
Expand All @@ -328,7 +328,7 @@ class SBBMenuItemState<T, W extends SBBMenuItem<T>> extends State<W>
mouseCursor: effectiveMouseCursor,
onHover: widget.enabled
? updateMaterialState(
MaterialState.hovered,
WidgetState.hovered,
)
: null,
child: _buildChild(),
Expand Down Expand Up @@ -364,10 +364,10 @@ class SBBMenuItemState<T, W extends SBBMenuItem<T>> extends State<W>
}

MouseCursor _getEffectiveMouseCursor() =>
MaterialStateProperty.resolveAs<MouseCursor>(
MaterialStateMouseCursor.clickable,
<MaterialState>{
if (!widget.enabled) MaterialState.disabled,
WidgetStateProperty.resolveAs<MouseCursor>(
WidgetStateMouseCursor.clickable,
<WidgetState>{
if (!widget.enabled) WidgetState.disabled,
},
);
}
Expand Down Expand Up @@ -980,8 +980,8 @@ class _SBBMenuTileItem<T> extends SBBMenuItem<T> {
vertical: 2.0,
),
TextStyle? textStyle,
MaterialStateProperty<Color?>? foregroundColor,
MaterialStateProperty<Color?>? backgroundColor,
WidgetStateProperty<Color?>? foregroundColor,
WidgetStateProperty<Color?>? backgroundColor,
IconData? icon,
required String title,
}) : super(
Expand Down
4 changes: 1 addition & 3 deletions lib/src/modal/sbb_modal.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dart:ui' as ui;

import 'package:flutter/material.dart';

import '../../design_system_flutter.dart';
Expand Down Expand Up @@ -186,7 +184,7 @@ class SBBModalSheet extends StatelessWidget {
@override
Widget build(BuildContext context) {
final style = SBBControlStyles.of(context);
final padding = MediaQueryData.fromWindow(ui.window).padding;
final padding = View.of(context).viewInsets;
final statusBarHeight = padding.top;
return Column(
mainAxisSize: MainAxisSize.min,
Expand Down
41 changes: 21 additions & 20 deletions lib/src/segmented_button/sbb_segmented_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -268,27 +268,28 @@ class _SegmentedButton extends State<SBBSegmentedButton> {
Widget _buildForegroundLayer() {
final loc = Localizations.of(context, MaterialLocalizations);
return IgnorePointer(
ignoringSemantics: false,
child: Row(
children: widget.widgetBuilders.mapIndexed((i, element) {
final selected = i == widget.selectedStateIndex;
return Expanded(
child: Semantics(
focusable: true,
selected: selected,
button: !selected,
hint: loc.tabLabel(
tabIndex: i + 1,
tabCount: widget.widgetBuilders.length,
),
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 4),
alignment: Alignment.center,
child: element(style, selected),
child: ExcludeSemantics(
child: Row(
children: widget.widgetBuilders.mapIndexed((i, element) {
final selected = i == widget.selectedStateIndex;
return Expanded(
child: Semantics(
focusable: true,
selected: selected,
button: !selected,
hint: loc.tabLabel(
tabIndex: i + 1,
tabCount: widget.widgetBuilders.length,
),
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 4),
alignment: Alignment.center,
child: element(style, selected),
),
),
),
);
}).toList(),
);
}).toList(),
),
),
);
}
Expand Down
Loading

0 comments on commit 32eb657

Please sign in to comment.