Unverified Commit f7f437ce authored by Taha Tesser's avatar Taha Tesser Committed by GitHub

Update Chips and `ChipTheme` tests and for Material 3 (#141022)

Updated unit tests for `Tooltip` to have M2 and M3 versions.

More info in #139076
parent 649877d2
......@@ -11,10 +11,9 @@ Widget wrapForChip({
TextDirection textDirection = TextDirection.ltr,
double textScaleFactor = 1.0,
Brightness brightness = Brightness.light,
bool? useMaterial3,
}) {
return MaterialApp(
theme: ThemeData(brightness: brightness, useMaterial3: useMaterial3),
theme: ThemeData(brightness: brightness),
home: Directionality(
textDirection: textDirection,
child: MediaQuery(
......@@ -72,8 +71,65 @@ void checkChipMaterialClipBehavior(WidgetTester tester, Clip clipBehavior) {
}
void main() {
testWidgets('ActionChip defaults', (WidgetTester tester) async {
final ThemeData theme = ThemeData(useMaterial3: true);
testWidgets('Material2 - ActionChip defaults', (WidgetTester tester) async {
final ThemeData theme = ThemeData(useMaterial3: false);
const String label = 'action chip';
// Test enabled ActionChip defaults.
await tester.pumpWidget(
MaterialApp(
theme: theme,
home: Material(
child: Center(
child: ActionChip(
onPressed: () {},
label: const Text(label),
),
),
),
),
);
// Test default chip size.
expect(tester.getSize(find.byType(ActionChip)), const Size(178.0, 48.0));
// Test default label style.
expect(
getLabelStyle(tester, label).style.color,
theme.textTheme.bodyLarge!.color!.withAlpha(0xde),
);
Material chipMaterial = getMaterial(tester);
expect(chipMaterial.elevation, 0);
expect(chipMaterial.shadowColor, Colors.black);
expect(chipMaterial.shape, const StadiumBorder());
ShapeDecoration decoration = tester.widget<Ink>(find.byType(Ink)).decoration! as ShapeDecoration;
expect(decoration.color, Colors.black.withAlpha(0x1f));
// Test disabled ActionChip defaults.
await tester.pumpWidget(
MaterialApp(
theme: theme,
home: const Material(
child: ActionChip(
label: Text(label),
),
),
),
);
await tester.pumpAndSettle();
chipMaterial = getMaterial(tester);
expect(chipMaterial.elevation, 0);
expect(chipMaterial.shadowColor, Colors.black);
expect(chipMaterial.shape, const StadiumBorder());
decoration = tester.widget<Ink>(find.byType(Ink)).decoration! as ShapeDecoration;
expect(decoration.color, Colors.black38);
});
testWidgets('Material3 - ActionChip defaults', (WidgetTester tester) async {
final ThemeData theme = ThemeData();
const String label = 'action chip';
// Test enabled ActionChip defaults.
......@@ -146,8 +202,8 @@ void main() {
expect(decoration.color, null);
});
testWidgets('ActionChip.elevated defaults', (WidgetTester tester) async {
final ThemeData theme = ThemeData(useMaterial3: true);
testWidgets('Material3 - ActionChip.elevated defaults', (WidgetTester tester) async {
final ThemeData theme = ThemeData();
const String label = 'action chip';
// Test enabled ActionChip defaults.
......@@ -231,7 +287,6 @@ void main() {
});
Widget buildApp({ required bool enabled, required bool selected }) {
return wrapForChip(
useMaterial3: true,
child: Column(
children: <Widget>[
ActionChip(
......@@ -284,7 +339,6 @@ void main() {
const Color backgroundColor = Color(0xff0000ff);
Widget buildApp({ required bool enabled, required bool selected }) {
return wrapForChip(
useMaterial3: true,
child: Column(
children: <Widget>[
ActionChip(
......
......@@ -159,11 +159,11 @@ void main() {
labelStyle: TextStyle(fontSize: 32),
iconTheme: IconThemeData(color: Color(0xff332211)),
);
final ThemeData theme = ThemeData(chipTheme: chipTheme, useMaterial3: true);
final ThemeData theme = ThemeData(chipTheme: chipTheme);
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(chipTheme: chipTheme, useMaterial3: true),
theme: ThemeData(chipTheme: chipTheme),
home: Directionality(
textDirection: TextDirection.ltr,
child: Material(
......@@ -239,7 +239,7 @@ void main() {
shape: RoundedRectangleBorder(),
iconTheme: IconThemeData(color: Color(0xff332211)),
);
final ThemeData theme = ThemeData(chipTheme: const ChipThemeData(), useMaterial3: true);
final ThemeData theme = ThemeData(chipTheme: const ChipThemeData());
await tester.pumpWidget(
MaterialApp(
......@@ -389,7 +389,6 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(useMaterial3: true),
home: Builder(
builder: (BuildContext context) {
return Directionality(
......@@ -773,7 +772,7 @@ void main() {
Widget chipWidget({ bool enabled = true, bool selected = false }) {
return MaterialApp(
theme: ThemeData(
chipTheme: ThemeData.light().chipTheme.copyWith(
chipTheme: ThemeData().chipTheme.copyWith(
labelStyle: labelStyle,
secondaryLabelStyle: labelStyle,
),
......@@ -831,7 +830,7 @@ void main() {
focusNode.dispose();
});
testWidgets('Chip uses stateful border side from resolveWith pattern', (WidgetTester tester) async {
testWidgets('Material2 - Chip uses stateful border side from resolveWith pattern', (WidgetTester tester) async {
const Color selectedColor = Color(0x00000001);
const Color defaultColor = Color(0x00000002);
......@@ -872,7 +871,47 @@ void main() {
expect(find.byType(RawChip), paints..rrect()..rrect(color: selectedColor));
});
testWidgets('Chip uses stateful border side from chip theme', (WidgetTester tester) async {
testWidgets('Material3 - Chip uses stateful border side from resolveWith pattern', (WidgetTester tester) async {
const Color selectedColor = Color(0x00000001);
const Color defaultColor = Color(0x00000002);
BorderSide getBorderSide(Set<MaterialState> states) {
Color color = defaultColor;
if (states.contains(MaterialState.selected)) {
color = selectedColor;
}
return BorderSide(color: color);
}
Widget chipWidget({ bool selected = false }) {
return MaterialApp(
theme: ThemeData(
chipTheme: ChipThemeData(
side: MaterialStateBorderSide.resolveWith(getBorderSide),
),
),
home: Scaffold(
body: ChoiceChip(
label: const Text('Chip'),
selected: selected,
onSelected: (_) {},
),
),
);
}
// Default.
await tester.pumpWidget(chipWidget());
expect(find.byType(RawChip), paints..drrect(color: defaultColor));
// Selected.
await tester.pumpWidget(chipWidget(selected: true));
expect(find.byType(RawChip), paints..drrect(color: selectedColor));
});
testWidgets('Material2 - Chip uses stateful border side from chip theme', (WidgetTester tester) async {
const Color selectedColor = Color(0x00000001);
const Color defaultColor = Color(0x00000002);
......@@ -914,12 +953,49 @@ void main() {
expect(find.byType(RawChip), paints..rrect()..rrect(color: selectedColor));
});
testWidgets('Chip uses stateful shape from chip theme', (WidgetTester tester) async {
testWidgets('Material3 - Chip uses stateful border side from chip theme', (WidgetTester tester) async {
const Color selectedColor = Color(0x00000001);
const Color defaultColor = Color(0x00000002);
BorderSide getBorderSide(Set<MaterialState> states) {
Color color = defaultColor;
if (states.contains(MaterialState.selected)) {
color = selectedColor;
}
return BorderSide(color: color);
}
final ChipThemeData chipTheme = ChipThemeData(
side: _MaterialStateBorderSide(getBorderSide),
);
Widget chipWidget({ bool selected = false }) {
return MaterialApp(
theme: ThemeData(chipTheme: chipTheme),
home: Scaffold(
body: ChoiceChip(
label: const Text('Chip'),
selected: selected,
onSelected: (_) {},
),
),
);
}
// Default.
await tester.pumpWidget(chipWidget());
expect(find.byType(RawChip), paints..drrect(color: defaultColor));
// Selected.
await tester.pumpWidget(chipWidget(selected: true));
expect(find.byType(RawChip), paints..drrect(color: selectedColor));
});
testWidgets('Material2 - Chip uses stateful shape from chip theme', (WidgetTester tester) async {
OutlinedBorder? getShape(Set<MaterialState> states) {
if (states.contains(MaterialState.selected)) {
return const RoundedRectangleBorder();
}
return null;
}
......@@ -931,7 +1007,6 @@ void main() {
shape: _MaterialStateOutlinedBorder(getShape),
);
Widget chipWidget({ bool selected = false }) {
return MaterialApp(
theme: ThemeData(useMaterial3: false, chipTheme: chipTheme),
......@@ -954,6 +1029,41 @@ void main() {
expect(getMaterial(tester).shape, isA<RoundedRectangleBorder>());
});
testWidgets('Material3 - Chip uses stateful shape from chip theme', (WidgetTester tester) async {
OutlinedBorder? getShape(Set<MaterialState> states) {
if (states.contains(MaterialState.selected)) {
return const StadiumBorder();
}
return null;
}
final ChipThemeData chipTheme = ChipThemeData(
shape: _MaterialStateOutlinedBorder(getShape),
);
Widget chipWidget({ bool selected = false }) {
return MaterialApp(
theme: ThemeData(chipTheme: chipTheme),
home: Scaffold(
body: ChoiceChip(
label: const Text('Chip'),
selected: selected,
onSelected: (_) {},
),
),
);
}
// Default.
await tester.pumpWidget(chipWidget());
expect(getMaterial(tester).shape, isA<RoundedRectangleBorder>());
// Selected.
await tester.pumpWidget(chipWidget(selected: true));
expect(getMaterial(tester).shape, isA<StadiumBorder>());
});
testWidgets('RawChip uses material state color from ChipTheme', (WidgetTester tester) async {
const Color disabledSelectedColor = Color(0xffffff00);
const Color disabledColor = Color(0xff00ff00);
......@@ -977,7 +1087,6 @@ void main() {
return backgroundColor;
}),
),
useMaterial3: true,
),
home: Material(
child: RawChip(
......@@ -1026,7 +1135,7 @@ void main() {
);
Widget buildApp({ required bool enabled, required bool selected }) {
return MaterialApp(
theme: ThemeData(chipTheme: chipTheme, useMaterial3: true),
theme: ThemeData(chipTheme: chipTheme),
home: Material(
child: RawChip(
isEnabled: enabled,
......@@ -1063,7 +1172,7 @@ void main() {
testWidgets('RawChip respects checkmark properties from ChipTheme', (WidgetTester tester) async {
Widget buildRawChip({ChipThemeData? chipTheme}) {
return MaterialApp(
theme: ThemeData.light(useMaterial3: false).copyWith(
theme: ThemeData(
chipTheme: chipTheme,
),
home: Directionality(
......@@ -1120,7 +1229,6 @@ void main() {
Widget buildChip({ OutlinedBorder? shape, BorderSide? side }) {
return MaterialApp(
theme: ThemeData(
useMaterial3: true,
chipTheme: ChipThemeData(
shape: shape,
side: side,
......@@ -1177,7 +1285,7 @@ void main() {
testWidgets('Material3 - ChipThemeData.iconTheme respects default iconTheme.size', (WidgetTester tester) async {
Widget buildChip({ IconThemeData? iconTheme }) {
return MaterialApp(
theme: ThemeData(useMaterial3: true, chipTheme: ChipThemeData(iconTheme: iconTheme)),
theme: ThemeData(chipTheme: ChipThemeData(iconTheme: iconTheme)),
home: Directionality(
textDirection: TextDirection.ltr,
child: Material(
......
......@@ -72,8 +72,112 @@ void checkChipMaterialClipBehavior(WidgetTester tester, Clip clipBehavior) {
}
void main() {
testWidgets('ChoiceChip defaults', (WidgetTester tester) async {
final ThemeData theme = ThemeData(useMaterial3: true);
testWidgets('Material2 - ChoiceChip defaults', (WidgetTester tester) async {
final ThemeData theme = ThemeData(useMaterial3: false);
const String label = 'choice chip';
// Test enabled ChoiceChip defaults.
await tester.pumpWidget(
MaterialApp(
theme: theme,
home: Material(
child: Center(
child: ChoiceChip(
selected: false,
onSelected: (bool valueChanged) { },
label: const Text(label),
),
),
),
),
);
// Test default chip size.
expect(tester.getSize(find.byType(ChoiceChip)), const Size(178.0, 48.0));
// Test default label style.
expect(
getLabelStyle(tester, label).style.color,
theme.textTheme.bodyLarge!.color!.withAlpha(0xde),
);
Material chipMaterial = getMaterial(tester);
expect(chipMaterial.elevation, 0);
expect(chipMaterial.shadowColor, Colors.black);
expect(chipMaterial.shape, const StadiumBorder());
ShapeDecoration decoration = tester.widget<Ink>(find.byType(Ink)).decoration! as ShapeDecoration;
expect(decoration.color, Colors.black.withAlpha(0x1f));
// Test disabled ChoiceChip defaults.
await tester.pumpWidget(
MaterialApp(
theme: theme,
home: const Material(
child: ChoiceChip(
selected: false,
label: Text(label),
),
),
),
);
await tester.pumpAndSettle();
chipMaterial = getMaterial(tester);
expect(chipMaterial.elevation, 0);
expect(chipMaterial.shadowColor, Colors.black);
expect(chipMaterial.shape, const StadiumBorder());
decoration = tester.widget<Ink>(find.byType(Ink)).decoration! as ShapeDecoration;
expect(decoration.color, Colors.black38);
// Test selected enabled ChoiceChip defaults.
await tester.pumpWidget(
MaterialApp(
theme: theme,
home: Material(
child: ChoiceChip(
selected: true,
onSelected: (bool valueChanged) { },
label: const Text(label),
),
),
),
);
await tester.pumpAndSettle();
chipMaterial = getMaterial(tester);
expect(chipMaterial.elevation, 0);
expect(chipMaterial.shadowColor, Colors.black);
expect(chipMaterial.shape, const StadiumBorder());
decoration = tester.widget<Ink>(find.byType(Ink)).decoration! as ShapeDecoration;
expect(decoration.color, Colors.black.withAlpha(0x3d));
// Test selected disabled ChoiceChip defaults.
await tester.pumpWidget(
MaterialApp(
theme: theme,
home: const Material(
child: ChoiceChip(
selected: true,
label: Text(label),
),
),
),
);
await tester.pumpAndSettle();
chipMaterial = getMaterial(tester);
expect(chipMaterial.elevation, 0);
expect(chipMaterial.shadowColor, Colors.black);
expect(chipMaterial.shape, const StadiumBorder());
decoration = tester.widget<Ink>(find.byType(Ink)).decoration! as ShapeDecoration;
expect(decoration.color, Colors.black.withAlpha(0x3d));
});
testWidgets('Material3 - ChoiceChip defaults', (WidgetTester tester) async {
final ThemeData theme = ThemeData();
const String label = 'choice chip';
// Test enabled ChoiceChip defaults.
......@@ -207,8 +311,8 @@ void main() {
expect(decoration.color, theme.colorScheme.onSurface.withOpacity(0.12));
});
testWidgets('ChoiceChip.elevated defaults', (WidgetTester tester) async {
final ThemeData theme = ThemeData(useMaterial3: true);
testWidgets('Material3 - ChoiceChip.elevated defaults', (WidgetTester tester) async {
final ThemeData theme = ThemeData();
const String label = 'choice chip';
// Test enabled ChoiceChip.elevated defaults.
......@@ -556,15 +660,16 @@ void main() {
testWidgets('ChoiceChip passes showCheckmark from ChipTheme to RawChip', (WidgetTester tester) async {
const bool showCheckmark = false;
await tester.pumpWidget(wrapForChip(
child: const ChipTheme(
data: ChipThemeData(
showCheckmark: showCheckmark,
),
child: ChoiceChip(
label: Text('Test'),
selected: true,
),
)));
child: const ChipTheme(
data: ChipThemeData(
showCheckmark: showCheckmark,
),
child: ChoiceChip(
label: Text('Test'),
selected: true,
),
),
));
final RawChip rawChip = tester.widget(find.byType(RawChip));
expect(rawChip.showCheckmark, showCheckmark);
});
......@@ -578,7 +683,8 @@ void main() {
selected: true,
showCheckmark: showCheckmark,
checkmarkColor: checkmarkColor,
)));
),
));
final RawChip rawChip = tester.widget(find.byType(RawChip));
expect(rawChip.showCheckmark, showCheckmark);
expect(rawChip.checkmarkColor, checkmarkColor);
......@@ -609,43 +715,4 @@ void main() {
expect(getIconData(tester).color, const Color(0xff00ff00));
});
group('Material 2', () {
// These tests are only relevant for Material 2. Once Material 2
// support is deprecated and the APIs are removed, these tests
// can be deleted.
testWidgets('ChoiceChip defaults', (WidgetTester tester) async {
Widget buildFrame(Brightness brightness) {
return MaterialApp(
theme: ThemeData(useMaterial3: false, brightness: brightness),
home: const Scaffold(
body: Center(
child: ChoiceChip(
label: Text('Chip A'),
selected: true,
),
),
),
);
}
await tester.pumpWidget(buildFrame(Brightness.light));
expect(getMaterialBox(tester, find.byType(RawChip)), paints..rrect(color: const Color(0x3d000000)));
expect(tester.getSize(find.byType(ChoiceChip)), const Size(108.0, 48.0));
expect(getMaterial(tester).color, null);
expect(getMaterial(tester).elevation, 0);
expect(getMaterial(tester).shape, const StadiumBorder());
expect(getLabelStyle(tester, 'Chip A').style.color?.value, 0xde000000);
await tester.pumpWidget(buildFrame(Brightness.dark));
await tester.pumpAndSettle(); // Theme transition animation
expect(getMaterialBox(tester, find.byType(RawChip)), paints..rrect(color: const Color(0x3dffffff)));
expect(tester.getSize(find.byType(ChoiceChip)), const Size(108.0, 48.0));
expect(getMaterial(tester).color, null);
expect(getMaterial(tester).elevation, 0);
expect(getMaterial(tester).shape, const StadiumBorder());
expect(getLabelStyle(tester, 'Chip A').style.color?.value, 0xdeffffff);
});
});
}
......@@ -38,11 +38,11 @@ Future<void> pumpCheckmarkChip(
required Widget chip,
Color? themeColor,
Brightness brightness = Brightness.light,
ThemeData? theme,
bool? useMaterial3,
}) async {
await tester.pumpWidget(
wrapForChip(
useMaterial3: false,
useMaterial3: useMaterial3,
brightness: brightness,
child: Builder(
builder: (BuildContext context) {
......@@ -131,8 +131,113 @@ DefaultTextStyle getLabelStyle(WidgetTester tester, String labelText) {
}
void main() {
testWidgets('FilterChip defaults', (WidgetTester tester) async {
final ThemeData theme = ThemeData(useMaterial3: true);
testWidgets('Material2 - FilterChip defaults', (WidgetTester tester) async {
final ThemeData theme = ThemeData(useMaterial3: false);
const String label = 'filter chip';
// Test enabled FilterChip defaults.
await tester.pumpWidget(
MaterialApp(
theme: theme,
home: Material(
child: Center(
child: FilterChip(
onSelected: (bool valueChanged) { },
label: const Text(label),
),
),
),
),
);
// Test default chip size.
expect(tester.getSize(find.byType(FilterChip)), const Size(178.0, 48.0));
// Test default label style.
expect(
getLabelStyle(tester, label).style.color,
theme.textTheme.bodyLarge!.color!.withAlpha(0xde),
);
Material chipMaterial = getMaterial(tester);
expect(chipMaterial.elevation, 0);
expect(chipMaterial.shadowColor, Colors.black);
expect(chipMaterial.shape, const StadiumBorder());
ShapeDecoration decoration = tester.widget<Ink>(find.byType(Ink)).decoration! as ShapeDecoration;
expect(decoration.color, Colors.black.withAlpha(0x1f));
// Test disabled FilterChip defaults.
await tester.pumpWidget(
MaterialApp(
theme: theme,
home: const Material(
child: FilterChip(
onSelected: null,
label: Text(label),
),
),
),
);
await tester.pumpAndSettle();
chipMaterial = getMaterial(tester);
expect(chipMaterial.elevation, 0);
expect(chipMaterial.shadowColor, Colors.black);
expect(chipMaterial.shape, const StadiumBorder());
decoration = tester.widget<Ink>(find.byType(Ink)).decoration! as ShapeDecoration;
expect(decoration.color, Colors.black38);
// Test selected enabled FilterChip defaults.
await tester.pumpWidget(
MaterialApp(
theme: theme,
home: Material(
child: FilterChip(
selected: true,
onSelected: (bool valueChanged) { },
label: const Text(label),
),
),
),
);
await tester.pumpAndSettle();
chipMaterial = getMaterial(tester);
expect(chipMaterial.elevation, 0);
expect(chipMaterial.shadowColor, Colors.black);
expect(chipMaterial.shape, const StadiumBorder());
decoration = tester.widget<Ink>(find.byType(Ink)).decoration! as ShapeDecoration;
expect(decoration.color, Colors.black.withAlpha(0x3d));
// Test selected disabled FilterChip defaults.
await tester.pumpWidget(
MaterialApp(
theme: theme,
home: const Material(
child: FilterChip(
selected: true,
onSelected: null,
label: Text(label),
),
),
),
);
await tester.pumpAndSettle();
chipMaterial = getMaterial(tester);
expect(chipMaterial.elevation, 0);
expect(chipMaterial.shadowColor, Colors.black);
expect(chipMaterial.shape, const StadiumBorder());
decoration = tester.widget<Ink>(find.byType(Ink)).decoration! as ShapeDecoration;
expect(decoration.color, Colors.black.withAlpha(0x3d));
});
testWidgets('Material3 - FilterChip defaults', (WidgetTester tester) async {
final ThemeData theme = ThemeData();
const String label = 'filter chip';
// Test enabled FilterChip defaults.
......@@ -266,8 +371,8 @@ void main() {
expect(decoration.color, theme.colorScheme.onSurface.withOpacity(0.12));
});
testWidgets('FilterChip.elevated defaults', (WidgetTester tester) async {
final ThemeData theme = ThemeData(useMaterial3: true);
testWidgets('Material3 - FilterChip.elevated defaults', (WidgetTester tester) async {
final ThemeData theme = ThemeData();
const String label = 'filter chip';
// Test enabled FilterChip.elevated defaults.
......@@ -420,7 +525,6 @@ void main() {
});
Widget buildApp({ required bool enabled, required bool selected }) {
return wrapForChip(
useMaterial3: true,
child: Column(
children: <Widget>[
FilterChip(
......@@ -507,7 +611,6 @@ void main() {
const Color selectedColor = Color(0xffff0000);
Widget buildApp({ required bool enabled, required bool selected }) {
return wrapForChip(
useMaterial3: true,
child: Column(
children: <Widget>[
FilterChip(
......@@ -592,25 +695,36 @@ void main() {
expect(tester.takeException(), null);
});
testWidgets('Filter chip check mark color is determined by platform brightness when light', (WidgetTester tester) async {
testWidgets('Material2 - Filter chip check mark color is determined by platform brightness when light', (WidgetTester tester) async {
await pumpCheckmarkChip(
theme: ThemeData(useMaterial3: false),
tester,
chip: selectedFilterChip(),
useMaterial3: false,
);
expectCheckmarkColor(find.byType(FilterChip), Colors.black.withAlpha(0xde));
});
testWidgets('Material3 - Filter chip check mark color is determined by platform brightness when light', (WidgetTester tester) async {
final ThemeData theme = ThemeData();
await pumpCheckmarkChip(
tester,
chip: selectedFilterChip(),
useMaterial3: theme.useMaterial3,
);
expectCheckmarkColor(
find.byType(FilterChip),
Colors.black.withAlpha(0xde),
theme.colorScheme.onSecondaryContainer,
);
});
testWidgets('Filter chip check mark color is determined by platform brightness when dark', (WidgetTester tester) async {
testWidgets('Material2 - Filter chip check mark color is determined by platform brightness when dark', (WidgetTester tester) async {
await pumpCheckmarkChip(
tester,
chip: selectedFilterChip(),
brightness: Brightness.dark,
theme: ThemeData(useMaterial3: false),
useMaterial3: false,
);
expectCheckmarkColor(
......@@ -619,17 +733,29 @@ void main() {
);
});
testWidgets('Filter chip check mark color can be set by the chip theme', (WidgetTester tester) async {
testWidgets('Material3 - Filter chip check mark color is determined by platform brightness when dark', (WidgetTester tester) async {
final ThemeData theme = ThemeData(brightness: Brightness.dark);
await pumpCheckmarkChip(
tester,
chip: selectedFilterChip(),
themeColor: const Color(0xff00ff00),
brightness: theme.brightness,
useMaterial3: theme.useMaterial3,
);
expectCheckmarkColor(
find.byType(FilterChip),
const Color(0xff00ff00),
theme.colorScheme.onSecondaryContainer,
);
});
testWidgets('Filter chip check mark color can be set by the chip theme', (WidgetTester tester) async {
await pumpCheckmarkChip(
tester,
chip: selectedFilterChip(),
themeColor: const Color(0xff00ff00),
);
expectCheckmarkColor(find.byType(FilterChip), const Color(0xff00ff00));
});
testWidgets('Filter chip check mark color can be set by the chip constructor', (WidgetTester tester) async {
......@@ -638,10 +764,7 @@ void main() {
chip: selectedFilterChip(checkmarkColor: const Color(0xff00ff00)),
);
expectCheckmarkColor(
find.byType(FilterChip),
const Color(0xff00ff00),
);
expectCheckmarkColor(find.byType(FilterChip), const Color(0xff00ff00));
});
testWidgets('Filter chip check mark color is set by chip constructor even when a theme color is specified', (WidgetTester tester) async {
......@@ -651,10 +774,7 @@ void main() {
themeColor: const Color(0xff00ff00),
);
expectCheckmarkColor(
find.byType(FilterChip),
const Color(0xffff0000),
);
expectCheckmarkColor(find.byType(FilterChip), const Color(0xffff0000));
});
testWidgets('FilterChip clipBehavior properly passes through to the Material', (WidgetTester tester) async {
......@@ -666,7 +786,7 @@ void main() {
checkChipMaterialClipBehavior(tester, Clip.antiAlias);
});
testWidgets('M3 width should not change with selection', (WidgetTester tester) async {
testWidgets('Material3 - width should not change with selection', (WidgetTester tester) async {
// Regression tests for: https://github.com/flutter/flutter/issues/110645
// For the text "FilterChip" the chip should default to 175 regardless of selection.
......@@ -674,7 +794,6 @@ void main() {
// Unselected
await tester.pumpWidget(MaterialApp(
theme: ThemeData(useMaterial3: true),
home: Material(
child: Center(
child: FilterChip(
......@@ -689,7 +808,6 @@ void main() {
// Selected
await tester.pumpWidget(MaterialApp(
theme: ThemeData(useMaterial3: true),
home: Material(
child: Center(
child: FilterChip(
......@@ -832,14 +950,12 @@ void main() {
});
testWidgets('Customize FilterChip delete button', (WidgetTester tester) async {
final ThemeData theme = ThemeData();
Widget buildChip({
Widget? deleteIcon,
Color? deleteIconColor,
String? deleteButtonTooltipMessage,
}) {
return MaterialApp(
theme: theme,
home: Material(
child: Center(
child: FilterChip(
......
......@@ -49,7 +49,7 @@ Future<void> pumpCheckmarkChip(
required Widget chip,
Color? themeColor,
Brightness brightness = Brightness.light,
bool useMaterial3 = false,
bool? useMaterial3,
}) async {
await tester.pumpWidget(
wrapForChip(
......@@ -121,7 +121,6 @@ void main() {
const Color selectedColor = Color(0xffff0000);
Widget buildApp({ required bool enabled, required bool selected }) {
return wrapForChip(
useMaterial3: true,
child: InputChip(
onSelected: enabled ? (bool value) { } : null,
selected: selected,
......@@ -176,7 +175,6 @@ void main() {
const Color selectedColor = Color(0xffff0000);
Widget buildApp({ required bool enabled, required bool selected }) {
return wrapForChip(
useMaterial3: true,
child: InputChip(
onSelected: enabled ? (bool value) { } : null,
selected: selected,
......@@ -296,29 +294,41 @@ void main() {
focusNode2.dispose();
});
testWidgets('Input chip check mark color is determined by platform brightness when light', (WidgetTester tester) async {
testWidgets('Material2 - Input chip check mark color is determined by platform brightness when light', (WidgetTester tester) async {
await pumpCheckmarkChip(
tester,
chip: selectedInputChip(),
useMaterial3: false,
);
expectCheckmarkColor(
find.byType(InputChip),
Colors.black.withAlpha(0xde),
);
expectCheckmarkColor(find.byType(InputChip), Colors.black.withAlpha(0xde));
});
testWidgets('Material3 - Input chip check mark color is determined by platform brightness when light', (WidgetTester tester) async {
await pumpCheckmarkChip(tester, chip: selectedInputChip());
expectCheckmarkColor(find.byType(InputChip), Colors.black.withAlpha(0xde));
});
testWidgets('Input chip check mark color is determined by platform brightness when dark', (WidgetTester tester) async {
testWidgets('Material2 - Input chip check mark color is determined by platform brightness when dark', (WidgetTester tester) async {
await pumpCheckmarkChip(
tester,
chip: selectedInputChip(),
brightness: Brightness.dark,
useMaterial3: false,
);
expectCheckmarkColor(
find.byType(InputChip),
Colors.white.withAlpha(0xde),
expectCheckmarkColor(find.byType(InputChip), Colors.white.withAlpha(0xde));
});
testWidgets('Material3 - Input chip check mark color is determined by platform brightness when dark', (WidgetTester tester) async {
await pumpCheckmarkChip(
tester,
chip: selectedInputChip(),
brightness: Brightness.dark,
);
expectCheckmarkColor(find.byType(InputChip), Colors.white.withAlpha(0xde));
});
testWidgets('Input chip check mark color can be set by the chip theme', (WidgetTester tester) async {
......@@ -328,10 +338,7 @@ void main() {
themeColor: const Color(0xff00ff00),
);
expectCheckmarkColor(
find.byType(InputChip),
const Color(0xff00ff00),
);
expectCheckmarkColor(find.byType(InputChip), const Color(0xff00ff00));
});
testWidgets('Input chip check mark color can be set by the chip constructor', (WidgetTester tester) async {
......@@ -340,10 +347,7 @@ void main() {
chip: selectedInputChip(checkmarkColor: const Color(0xff00ff00)),
);
expectCheckmarkColor(
find.byType(InputChip),
const Color(0xff00ff00),
);
expectCheckmarkColor(find.byType(InputChip), const Color(0xff00ff00));
});
testWidgets('Input chip check mark color is set by chip constructor even when a theme color is specified', (WidgetTester tester) async {
......@@ -353,10 +357,7 @@ void main() {
themeColor: const Color(0xff00ff00),
);
expectCheckmarkColor(
find.byType(InputChip),
const Color(0xffff0000),
);
expectCheckmarkColor(find.byType(InputChip), const Color(0xffff0000));
});
testWidgets('InputChip clipBehavior properly passes through to the Material', (WidgetTester tester) async {
......@@ -368,7 +369,7 @@ void main() {
checkChipMaterialClipBehavior(tester, Clip.antiAlias);
});
testWidgets('Input chip has correct selected color when enabled - M3 defaults', (WidgetTester tester) async {
testWidgets('Material3 - Input chip has correct selected color when enabled', (WidgetTester tester) async {
final ChipThemeData material3ChipDefaults = ThemeData(useMaterial3: true).chipTheme;
await pumpCheckmarkChip(
tester,
......@@ -380,7 +381,7 @@ void main() {
expect(materialBox, paints..rrect(color: material3ChipDefaults.backgroundColor));
});
testWidgets('Input chip has correct selected color when disabled - M3 defaults', (WidgetTester tester) async {
testWidgets('Material3 - Input chip has correct selected color when disabled', (WidgetTester tester) async {
final ChipThemeData material3ChipDefaults = ThemeData(useMaterial3: true).chipTheme;
await pumpCheckmarkChip(
tester,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment