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({ ...@@ -11,10 +11,9 @@ Widget wrapForChip({
TextDirection textDirection = TextDirection.ltr, TextDirection textDirection = TextDirection.ltr,
double textScaleFactor = 1.0, double textScaleFactor = 1.0,
Brightness brightness = Brightness.light, Brightness brightness = Brightness.light,
bool? useMaterial3,
}) { }) {
return MaterialApp( return MaterialApp(
theme: ThemeData(brightness: brightness, useMaterial3: useMaterial3), theme: ThemeData(brightness: brightness),
home: Directionality( home: Directionality(
textDirection: textDirection, textDirection: textDirection,
child: MediaQuery( child: MediaQuery(
...@@ -72,8 +71,65 @@ void checkChipMaterialClipBehavior(WidgetTester tester, Clip clipBehavior) { ...@@ -72,8 +71,65 @@ void checkChipMaterialClipBehavior(WidgetTester tester, Clip clipBehavior) {
} }
void main() { void main() {
testWidgets('ActionChip defaults', (WidgetTester tester) async { testWidgets('Material2 - ActionChip defaults', (WidgetTester tester) async {
final ThemeData theme = ThemeData(useMaterial3: true); 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'; const String label = 'action chip';
// Test enabled ActionChip defaults. // Test enabled ActionChip defaults.
...@@ -146,8 +202,8 @@ void main() { ...@@ -146,8 +202,8 @@ void main() {
expect(decoration.color, null); expect(decoration.color, null);
}); });
testWidgets('ActionChip.elevated defaults', (WidgetTester tester) async { testWidgets('Material3 - ActionChip.elevated defaults', (WidgetTester tester) async {
final ThemeData theme = ThemeData(useMaterial3: true); final ThemeData theme = ThemeData();
const String label = 'action chip'; const String label = 'action chip';
// Test enabled ActionChip defaults. // Test enabled ActionChip defaults.
...@@ -231,7 +287,6 @@ void main() { ...@@ -231,7 +287,6 @@ void main() {
}); });
Widget buildApp({ required bool enabled, required bool selected }) { Widget buildApp({ required bool enabled, required bool selected }) {
return wrapForChip( return wrapForChip(
useMaterial3: true,
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
ActionChip( ActionChip(
...@@ -284,7 +339,6 @@ void main() { ...@@ -284,7 +339,6 @@ void main() {
const Color backgroundColor = Color(0xff0000ff); const Color backgroundColor = Color(0xff0000ff);
Widget buildApp({ required bool enabled, required bool selected }) { Widget buildApp({ required bool enabled, required bool selected }) {
return wrapForChip( return wrapForChip(
useMaterial3: true,
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
ActionChip( ActionChip(
......
...@@ -159,11 +159,11 @@ void main() { ...@@ -159,11 +159,11 @@ void main() {
labelStyle: TextStyle(fontSize: 32), labelStyle: TextStyle(fontSize: 32),
iconTheme: IconThemeData(color: Color(0xff332211)), iconTheme: IconThemeData(color: Color(0xff332211)),
); );
final ThemeData theme = ThemeData(chipTheme: chipTheme, useMaterial3: true); final ThemeData theme = ThemeData(chipTheme: chipTheme);
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData(chipTheme: chipTheme, useMaterial3: true), theme: ThemeData(chipTheme: chipTheme),
home: Directionality( home: Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: Material( child: Material(
...@@ -239,7 +239,7 @@ void main() { ...@@ -239,7 +239,7 @@ void main() {
shape: RoundedRectangleBorder(), shape: RoundedRectangleBorder(),
iconTheme: IconThemeData(color: Color(0xff332211)), iconTheme: IconThemeData(color: Color(0xff332211)),
); );
final ThemeData theme = ThemeData(chipTheme: const ChipThemeData(), useMaterial3: true); final ThemeData theme = ThemeData(chipTheme: const ChipThemeData());
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
...@@ -389,7 +389,6 @@ void main() { ...@@ -389,7 +389,6 @@ void main() {
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData(useMaterial3: true),
home: Builder( home: Builder(
builder: (BuildContext context) { builder: (BuildContext context) {
return Directionality( return Directionality(
...@@ -773,7 +772,7 @@ void main() { ...@@ -773,7 +772,7 @@ void main() {
Widget chipWidget({ bool enabled = true, bool selected = false }) { Widget chipWidget({ bool enabled = true, bool selected = false }) {
return MaterialApp( return MaterialApp(
theme: ThemeData( theme: ThemeData(
chipTheme: ThemeData.light().chipTheme.copyWith( chipTheme: ThemeData().chipTheme.copyWith(
labelStyle: labelStyle, labelStyle: labelStyle,
secondaryLabelStyle: labelStyle, secondaryLabelStyle: labelStyle,
), ),
...@@ -831,7 +830,7 @@ void main() { ...@@ -831,7 +830,7 @@ void main() {
focusNode.dispose(); 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 selectedColor = Color(0x00000001);
const Color defaultColor = Color(0x00000002); const Color defaultColor = Color(0x00000002);
...@@ -872,7 +871,47 @@ void main() { ...@@ -872,7 +871,47 @@ void main() {
expect(find.byType(RawChip), paints..rrect()..rrect(color: selectedColor)); 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 selectedColor = Color(0x00000001);
const Color defaultColor = Color(0x00000002); const Color defaultColor = Color(0x00000002);
...@@ -914,12 +953,49 @@ void main() { ...@@ -914,12 +953,49 @@ void main() {
expect(find.byType(RawChip), paints..rrect()..rrect(color: selectedColor)); 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) { OutlinedBorder? getShape(Set<MaterialState> states) {
if (states.contains(MaterialState.selected)) { if (states.contains(MaterialState.selected)) {
return const RoundedRectangleBorder(); return const RoundedRectangleBorder();
} }
return null; return null;
} }
...@@ -931,7 +1007,6 @@ void main() { ...@@ -931,7 +1007,6 @@ void main() {
shape: _MaterialStateOutlinedBorder(getShape), shape: _MaterialStateOutlinedBorder(getShape),
); );
Widget chipWidget({ bool selected = false }) { Widget chipWidget({ bool selected = false }) {
return MaterialApp( return MaterialApp(
theme: ThemeData(useMaterial3: false, chipTheme: chipTheme), theme: ThemeData(useMaterial3: false, chipTheme: chipTheme),
...@@ -954,6 +1029,41 @@ void main() { ...@@ -954,6 +1029,41 @@ void main() {
expect(getMaterial(tester).shape, isA<RoundedRectangleBorder>()); 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 { testWidgets('RawChip uses material state color from ChipTheme', (WidgetTester tester) async {
const Color disabledSelectedColor = Color(0xffffff00); const Color disabledSelectedColor = Color(0xffffff00);
const Color disabledColor = Color(0xff00ff00); const Color disabledColor = Color(0xff00ff00);
...@@ -977,7 +1087,6 @@ void main() { ...@@ -977,7 +1087,6 @@ void main() {
return backgroundColor; return backgroundColor;
}), }),
), ),
useMaterial3: true,
), ),
home: Material( home: Material(
child: RawChip( child: RawChip(
...@@ -1026,7 +1135,7 @@ void main() { ...@@ -1026,7 +1135,7 @@ void main() {
); );
Widget buildApp({ required bool enabled, required bool selected }) { Widget buildApp({ required bool enabled, required bool selected }) {
return MaterialApp( return MaterialApp(
theme: ThemeData(chipTheme: chipTheme, useMaterial3: true), theme: ThemeData(chipTheme: chipTheme),
home: Material( home: Material(
child: RawChip( child: RawChip(
isEnabled: enabled, isEnabled: enabled,
...@@ -1063,7 +1172,7 @@ void main() { ...@@ -1063,7 +1172,7 @@ void main() {
testWidgets('RawChip respects checkmark properties from ChipTheme', (WidgetTester tester) async { testWidgets('RawChip respects checkmark properties from ChipTheme', (WidgetTester tester) async {
Widget buildRawChip({ChipThemeData? chipTheme}) { Widget buildRawChip({ChipThemeData? chipTheme}) {
return MaterialApp( return MaterialApp(
theme: ThemeData.light(useMaterial3: false).copyWith( theme: ThemeData(
chipTheme: chipTheme, chipTheme: chipTheme,
), ),
home: Directionality( home: Directionality(
...@@ -1120,7 +1229,6 @@ void main() { ...@@ -1120,7 +1229,6 @@ void main() {
Widget buildChip({ OutlinedBorder? shape, BorderSide? side }) { Widget buildChip({ OutlinedBorder? shape, BorderSide? side }) {
return MaterialApp( return MaterialApp(
theme: ThemeData( theme: ThemeData(
useMaterial3: true,
chipTheme: ChipThemeData( chipTheme: ChipThemeData(
shape: shape, shape: shape,
side: side, side: side,
...@@ -1177,7 +1285,7 @@ void main() { ...@@ -1177,7 +1285,7 @@ void main() {
testWidgets('Material3 - ChipThemeData.iconTheme respects default iconTheme.size', (WidgetTester tester) async { testWidgets('Material3 - ChipThemeData.iconTheme respects default iconTheme.size', (WidgetTester tester) async {
Widget buildChip({ IconThemeData? iconTheme }) { Widget buildChip({ IconThemeData? iconTheme }) {
return MaterialApp( return MaterialApp(
theme: ThemeData(useMaterial3: true, chipTheme: ChipThemeData(iconTheme: iconTheme)), theme: ThemeData(chipTheme: ChipThemeData(iconTheme: iconTheme)),
home: Directionality( home: Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: Material( child: Material(
......
...@@ -72,8 +72,112 @@ void checkChipMaterialClipBehavior(WidgetTester tester, Clip clipBehavior) { ...@@ -72,8 +72,112 @@ void checkChipMaterialClipBehavior(WidgetTester tester, Clip clipBehavior) {
} }
void main() { void main() {
testWidgets('ChoiceChip defaults', (WidgetTester tester) async { testWidgets('Material2 - ChoiceChip defaults', (WidgetTester tester) async {
final ThemeData theme = ThemeData(useMaterial3: true); 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'; const String label = 'choice chip';
// Test enabled ChoiceChip defaults. // Test enabled ChoiceChip defaults.
...@@ -207,8 +311,8 @@ void main() { ...@@ -207,8 +311,8 @@ void main() {
expect(decoration.color, theme.colorScheme.onSurface.withOpacity(0.12)); expect(decoration.color, theme.colorScheme.onSurface.withOpacity(0.12));
}); });
testWidgets('ChoiceChip.elevated defaults', (WidgetTester tester) async { testWidgets('Material3 - ChoiceChip.elevated defaults', (WidgetTester tester) async {
final ThemeData theme = ThemeData(useMaterial3: true); final ThemeData theme = ThemeData();
const String label = 'choice chip'; const String label = 'choice chip';
// Test enabled ChoiceChip.elevated defaults. // Test enabled ChoiceChip.elevated defaults.
...@@ -556,15 +660,16 @@ void main() { ...@@ -556,15 +660,16 @@ void main() {
testWidgets('ChoiceChip passes showCheckmark from ChipTheme to RawChip', (WidgetTester tester) async { testWidgets('ChoiceChip passes showCheckmark from ChipTheme to RawChip', (WidgetTester tester) async {
const bool showCheckmark = false; const bool showCheckmark = false;
await tester.pumpWidget(wrapForChip( await tester.pumpWidget(wrapForChip(
child: const ChipTheme( child: const ChipTheme(
data: ChipThemeData( data: ChipThemeData(
showCheckmark: showCheckmark, showCheckmark: showCheckmark,
), ),
child: ChoiceChip( child: ChoiceChip(
label: Text('Test'), label: Text('Test'),
selected: true, selected: true,
), ),
))); ),
));
final RawChip rawChip = tester.widget(find.byType(RawChip)); final RawChip rawChip = tester.widget(find.byType(RawChip));
expect(rawChip.showCheckmark, showCheckmark); expect(rawChip.showCheckmark, showCheckmark);
}); });
...@@ -578,7 +683,8 @@ void main() { ...@@ -578,7 +683,8 @@ void main() {
selected: true, selected: true,
showCheckmark: showCheckmark, showCheckmark: showCheckmark,
checkmarkColor: checkmarkColor, checkmarkColor: checkmarkColor,
))); ),
));
final RawChip rawChip = tester.widget(find.byType(RawChip)); final RawChip rawChip = tester.widget(find.byType(RawChip));
expect(rawChip.showCheckmark, showCheckmark); expect(rawChip.showCheckmark, showCheckmark);
expect(rawChip.checkmarkColor, checkmarkColor); expect(rawChip.checkmarkColor, checkmarkColor);
...@@ -609,43 +715,4 @@ void main() { ...@@ -609,43 +715,4 @@ void main() {
expect(getIconData(tester).color, const Color(0xff00ff00)); 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( ...@@ -38,11 +38,11 @@ Future<void> pumpCheckmarkChip(
required Widget chip, required Widget chip,
Color? themeColor, Color? themeColor,
Brightness brightness = Brightness.light, Brightness brightness = Brightness.light,
ThemeData? theme, bool? useMaterial3,
}) async { }) async {
await tester.pumpWidget( await tester.pumpWidget(
wrapForChip( wrapForChip(
useMaterial3: false, useMaterial3: useMaterial3,
brightness: brightness, brightness: brightness,
child: Builder( child: Builder(
builder: (BuildContext context) { builder: (BuildContext context) {
...@@ -131,8 +131,113 @@ DefaultTextStyle getLabelStyle(WidgetTester tester, String labelText) { ...@@ -131,8 +131,113 @@ DefaultTextStyle getLabelStyle(WidgetTester tester, String labelText) {
} }
void main() { void main() {
testWidgets('FilterChip defaults', (WidgetTester tester) async { testWidgets('Material2 - FilterChip defaults', (WidgetTester tester) async {
final ThemeData theme = ThemeData(useMaterial3: true); 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'; const String label = 'filter chip';
// Test enabled FilterChip defaults. // Test enabled FilterChip defaults.
...@@ -266,8 +371,8 @@ void main() { ...@@ -266,8 +371,8 @@ void main() {
expect(decoration.color, theme.colorScheme.onSurface.withOpacity(0.12)); expect(decoration.color, theme.colorScheme.onSurface.withOpacity(0.12));
}); });
testWidgets('FilterChip.elevated defaults', (WidgetTester tester) async { testWidgets('Material3 - FilterChip.elevated defaults', (WidgetTester tester) async {
final ThemeData theme = ThemeData(useMaterial3: true); final ThemeData theme = ThemeData();
const String label = 'filter chip'; const String label = 'filter chip';
// Test enabled FilterChip.elevated defaults. // Test enabled FilterChip.elevated defaults.
...@@ -420,7 +525,6 @@ void main() { ...@@ -420,7 +525,6 @@ void main() {
}); });
Widget buildApp({ required bool enabled, required bool selected }) { Widget buildApp({ required bool enabled, required bool selected }) {
return wrapForChip( return wrapForChip(
useMaterial3: true,
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
FilterChip( FilterChip(
...@@ -507,7 +611,6 @@ void main() { ...@@ -507,7 +611,6 @@ void main() {
const Color selectedColor = Color(0xffff0000); const Color selectedColor = Color(0xffff0000);
Widget buildApp({ required bool enabled, required bool selected }) { Widget buildApp({ required bool enabled, required bool selected }) {
return wrapForChip( return wrapForChip(
useMaterial3: true,
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
FilterChip( FilterChip(
...@@ -592,25 +695,36 @@ void main() { ...@@ -592,25 +695,36 @@ void main() {
expect(tester.takeException(), null); 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( await pumpCheckmarkChip(
theme: ThemeData(useMaterial3: false),
tester, tester,
chip: selectedFilterChip(), 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( expectCheckmarkColor(
find.byType(FilterChip), 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( await pumpCheckmarkChip(
tester, tester,
chip: selectedFilterChip(), chip: selectedFilterChip(),
brightness: Brightness.dark, brightness: Brightness.dark,
theme: ThemeData(useMaterial3: false), useMaterial3: false,
); );
expectCheckmarkColor( expectCheckmarkColor(
...@@ -619,17 +733,29 @@ void main() { ...@@ -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( await pumpCheckmarkChip(
tester, tester,
chip: selectedFilterChip(), chip: selectedFilterChip(),
themeColor: const Color(0xff00ff00), brightness: theme.brightness,
useMaterial3: theme.useMaterial3,
); );
expectCheckmarkColor( expectCheckmarkColor(
find.byType(FilterChip), 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 { testWidgets('Filter chip check mark color can be set by the chip constructor', (WidgetTester tester) async {
...@@ -638,10 +764,7 @@ void main() { ...@@ -638,10 +764,7 @@ void main() {
chip: selectedFilterChip(checkmarkColor: const Color(0xff00ff00)), chip: selectedFilterChip(checkmarkColor: const Color(0xff00ff00)),
); );
expectCheckmarkColor( expectCheckmarkColor(find.byType(FilterChip), const Color(0xff00ff00));
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 { 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() { ...@@ -651,10 +774,7 @@ void main() {
themeColor: const Color(0xff00ff00), themeColor: const Color(0xff00ff00),
); );
expectCheckmarkColor( expectCheckmarkColor(find.byType(FilterChip), const Color(0xffff0000));
find.byType(FilterChip),
const Color(0xffff0000),
);
}); });
testWidgets('FilterChip clipBehavior properly passes through to the Material', (WidgetTester tester) async { testWidgets('FilterChip clipBehavior properly passes through to the Material', (WidgetTester tester) async {
...@@ -666,7 +786,7 @@ void main() { ...@@ -666,7 +786,7 @@ void main() {
checkChipMaterialClipBehavior(tester, Clip.antiAlias); 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 // Regression tests for: https://github.com/flutter/flutter/issues/110645
// For the text "FilterChip" the chip should default to 175 regardless of selection. // For the text "FilterChip" the chip should default to 175 regardless of selection.
...@@ -674,7 +794,6 @@ void main() { ...@@ -674,7 +794,6 @@ void main() {
// Unselected // Unselected
await tester.pumpWidget(MaterialApp( await tester.pumpWidget(MaterialApp(
theme: ThemeData(useMaterial3: true),
home: Material( home: Material(
child: Center( child: Center(
child: FilterChip( child: FilterChip(
...@@ -689,7 +808,6 @@ void main() { ...@@ -689,7 +808,6 @@ void main() {
// Selected // Selected
await tester.pumpWidget(MaterialApp( await tester.pumpWidget(MaterialApp(
theme: ThemeData(useMaterial3: true),
home: Material( home: Material(
child: Center( child: Center(
child: FilterChip( child: FilterChip(
...@@ -832,14 +950,12 @@ void main() { ...@@ -832,14 +950,12 @@ void main() {
}); });
testWidgets('Customize FilterChip delete button', (WidgetTester tester) async { testWidgets('Customize FilterChip delete button', (WidgetTester tester) async {
final ThemeData theme = ThemeData();
Widget buildChip({ Widget buildChip({
Widget? deleteIcon, Widget? deleteIcon,
Color? deleteIconColor, Color? deleteIconColor,
String? deleteButtonTooltipMessage, String? deleteButtonTooltipMessage,
}) { }) {
return MaterialApp( return MaterialApp(
theme: theme,
home: Material( home: Material(
child: Center( child: Center(
child: FilterChip( child: FilterChip(
......
...@@ -49,7 +49,7 @@ Future<void> pumpCheckmarkChip( ...@@ -49,7 +49,7 @@ Future<void> pumpCheckmarkChip(
required Widget chip, required Widget chip,
Color? themeColor, Color? themeColor,
Brightness brightness = Brightness.light, Brightness brightness = Brightness.light,
bool useMaterial3 = false, bool? useMaterial3,
}) async { }) async {
await tester.pumpWidget( await tester.pumpWidget(
wrapForChip( wrapForChip(
...@@ -121,7 +121,6 @@ void main() { ...@@ -121,7 +121,6 @@ void main() {
const Color selectedColor = Color(0xffff0000); const Color selectedColor = Color(0xffff0000);
Widget buildApp({ required bool enabled, required bool selected }) { Widget buildApp({ required bool enabled, required bool selected }) {
return wrapForChip( return wrapForChip(
useMaterial3: true,
child: InputChip( child: InputChip(
onSelected: enabled ? (bool value) { } : null, onSelected: enabled ? (bool value) { } : null,
selected: selected, selected: selected,
...@@ -176,7 +175,6 @@ void main() { ...@@ -176,7 +175,6 @@ void main() {
const Color selectedColor = Color(0xffff0000); const Color selectedColor = Color(0xffff0000);
Widget buildApp({ required bool enabled, required bool selected }) { Widget buildApp({ required bool enabled, required bool selected }) {
return wrapForChip( return wrapForChip(
useMaterial3: true,
child: InputChip( child: InputChip(
onSelected: enabled ? (bool value) { } : null, onSelected: enabled ? (bool value) { } : null,
selected: selected, selected: selected,
...@@ -296,29 +294,41 @@ void main() { ...@@ -296,29 +294,41 @@ void main() {
focusNode2.dispose(); 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( await pumpCheckmarkChip(
tester, tester,
chip: selectedInputChip(), chip: selectedInputChip(),
useMaterial3: false,
); );
expectCheckmarkColor( expectCheckmarkColor(find.byType(InputChip), Colors.black.withAlpha(0xde));
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( await pumpCheckmarkChip(
tester, tester,
chip: selectedInputChip(), chip: selectedInputChip(),
brightness: Brightness.dark, brightness: Brightness.dark,
useMaterial3: false,
); );
expectCheckmarkColor( expectCheckmarkColor(find.byType(InputChip), Colors.white.withAlpha(0xde));
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 { testWidgets('Input chip check mark color can be set by the chip theme', (WidgetTester tester) async {
...@@ -328,10 +338,7 @@ void main() { ...@@ -328,10 +338,7 @@ void main() {
themeColor: const Color(0xff00ff00), themeColor: const Color(0xff00ff00),
); );
expectCheckmarkColor( expectCheckmarkColor(find.byType(InputChip), const Color(0xff00ff00));
find.byType(InputChip),
const Color(0xff00ff00),
);
}); });
testWidgets('Input chip check mark color can be set by the chip constructor', (WidgetTester tester) async { testWidgets('Input chip check mark color can be set by the chip constructor', (WidgetTester tester) async {
...@@ -340,10 +347,7 @@ void main() { ...@@ -340,10 +347,7 @@ void main() {
chip: selectedInputChip(checkmarkColor: const Color(0xff00ff00)), chip: selectedInputChip(checkmarkColor: const Color(0xff00ff00)),
); );
expectCheckmarkColor( expectCheckmarkColor(find.byType(InputChip), const Color(0xff00ff00));
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 { 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() { ...@@ -353,10 +357,7 @@ void main() {
themeColor: const Color(0xff00ff00), themeColor: const Color(0xff00ff00),
); );
expectCheckmarkColor( expectCheckmarkColor(find.byType(InputChip), const Color(0xffff0000));
find.byType(InputChip),
const Color(0xffff0000),
);
}); });
testWidgets('InputChip clipBehavior properly passes through to the Material', (WidgetTester tester) async { testWidgets('InputChip clipBehavior properly passes through to the Material', (WidgetTester tester) async {
...@@ -368,7 +369,7 @@ void main() { ...@@ -368,7 +369,7 @@ void main() {
checkChipMaterialClipBehavior(tester, Clip.antiAlias); 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; final ChipThemeData material3ChipDefaults = ThemeData(useMaterial3: true).chipTheme;
await pumpCheckmarkChip( await pumpCheckmarkChip(
tester, tester,
...@@ -380,7 +381,7 @@ void main() { ...@@ -380,7 +381,7 @@ void main() {
expect(materialBox, paints..rrect(color: material3ChipDefaults.backgroundColor)); 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; final ChipThemeData material3ChipDefaults = ThemeData(useMaterial3: true).chipTheme;
await pumpCheckmarkChip( await pumpCheckmarkChip(
tester, 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