Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YaruCheckedPopupMenuItem: add golden test #337

Merged
merged 3 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
73 changes: 40 additions & 33 deletions lib/src/controls/yaru_popup_menu_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import 'package:flutter/material.dart';
import 'package:yaru_icons/yaru_icons.dart';
import '../constants.dart';

const _kYaruCheckMarkSize = 18.0;

/// A generic wrapper around [PopupMenuButton] that is visually more consistent
/// to buttons and dialogs than [DropdownButton]
class YaruPopupMenuButton<T> extends StatelessWidget {
Expand Down Expand Up @@ -134,7 +136,7 @@ class _YaruCheckedPopupMenuItemState<T>
Widget buildChild() {
return IgnorePointer(
child: ListTile(
minLeadingWidth: 18,
minLeadingWidth: _kYaruCheckMarkSize,
enabled: widget.enabled,
leading: _YaruCheckMark(
checked: widget.checked,
Expand All @@ -159,39 +161,44 @@ class _YaruCheckMark extends StatelessWidget {
final borderColor = Theme.of(context).colorScheme.onSurface.withOpacity(
Theme.of(context).brightness == Brightness.light ? 0.4 : 1,
);
const size = 18.0;
const duration = 200;
return checked
? AnimatedContainer(
height: size,
width: size,
duration: const Duration(
milliseconds: duration,
),
decoration: BoxDecoration(
color: Theme.of(context).primaryColor,
borderRadius: BorderRadius.circular(4),
),
child: const Icon(
Icons.check,
color: Colors.white,
size: size,
),
)
: AnimatedContainer(
height: size,
width: size,
duration: const Duration(
milliseconds: duration,
),
decoration: BoxDecoration(
border: Border.all(
color: borderColor,
width: 2,
return SizedBox(
width: _kYaruCheckMarkSize,
height: double.infinity,
Feichtmeier marked this conversation as resolved.
Show resolved Hide resolved
child: Center(
child: checked
? AnimatedContainer(
height: _kYaruCheckMarkSize,
width: _kYaruCheckMarkSize,
duration: const Duration(
milliseconds: duration,
),
decoration: BoxDecoration(
color: Theme.of(context).primaryColor,
borderRadius: BorderRadius.circular(4),
),
child: const Icon(
Icons.check,
color: Colors.white,
size: _kYaruCheckMarkSize,
),
)
: AnimatedContainer(
height: _kYaruCheckMarkSize,
width: _kYaruCheckMarkSize,
duration: const Duration(
milliseconds: duration,
),
decoration: BoxDecoration(
border: Border.all(
color: borderColor,
width: 2,
),
borderRadius: BorderRadius.circular(4),
),
),
borderRadius: BorderRadius.circular(4),
),
);
),
);
}
}

Expand Down Expand Up @@ -242,7 +249,7 @@ class _YaruMultiSelectPopupMenuItemState<T>
Widget buildChild() {
return IgnorePointer(
child: ListTile(
minLeadingWidth: 18,
minLeadingWidth: _kYaruCheckMarkSize,
enabled: widget.enabled,
leading: _YaruCheckMark(checked: _checked),
title: widget.child,
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
71 changes: 71 additions & 0 deletions test/controls/yaru_popup_menu_item_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:yaru_widgets/yaru_widgets.dart';

import '../yaru_golden_tester.dart';

void main() {
testWidgets(
'golden images',
(tester) async {
final variant = goldenVariant.currentValue!;

await tester.pumpScaffold(
YaruPopupMenuButton(
child: const Text('Button'),
itemBuilder: (context) => [
for (var i = 0; i < 3; ++i)
YaruCheckedPopupMenuItem(
child: Text('YaruPopupMenuItem $i'),
checked: variant.hasState(MaterialState.selected),
enabled: !variant.hasState(MaterialState.disabled),
),
],
),
themeMode: variant.themeMode,
size: const Size(300, 200),
);
await tester.pumpAndSettle();

await tester.tap(find.byType(YaruPopupMenuButton));
await tester.pumpAndSettle();

if (variant.hasState(MaterialState.pressed)) {
await tester.down(find.text('YaruPopupMenuItem 0'));
await tester.pumpAndSettle();
} else if (variant.hasState(MaterialState.hovered)) {
await tester.hover(find.text('YaruPopupMenuItem 0'));
await tester.pumpAndSettle();
}

await expectLater(
find.byType(MaterialApp),
matchesGoldenFile(
'goldens/yaru_popup_menu_item-${variant.label}.png',
),
);
},
variant: goldenVariant,
tags: 'golden',
);
}

final goldenVariant = ValueVariant({
...goldenThemeVariants('unchecked', <MaterialState>{}),
...goldenThemeVariants('unchecked-disabled', {MaterialState.disabled}),
...goldenThemeVariants('unchecked-hovered', {MaterialState.hovered}),
...goldenThemeVariants('unchecked-pressed', {MaterialState.pressed}),
...goldenThemeVariants('checked', {MaterialState.selected}),
...goldenThemeVariants('checked-disabled', {
MaterialState.selected,
MaterialState.disabled,
}),
...goldenThemeVariants('checked-hovered', {
MaterialState.selected,
MaterialState.hovered,
}),
...goldenThemeVariants('checked-pressed', {
MaterialState.selected,
MaterialState.pressed,
}),
});
1 change: 1 addition & 0 deletions test/yaru_golden_tester.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ extension YaruGoldenTester on WidgetTester {
themeMode: themeMode,
theme: theme ?? yaruLight,
darkTheme: darkTheme ?? yaruDark,
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(child: widget),
),
Expand Down