Skip to content

Commit 9ab091f

Browse files
authored
Update CircleAvatar & DataTable tests for Material 3 (flutter#135901)
Updated unit tests for `CircleAvatar` & `DataTable` to have M2 and M3 versions. More info in flutter#127064
1 parent c899ce3 commit 9ab091f

File tree

2 files changed

+52
-5
lines changed

2 files changed

+52
-5
lines changed

packages/flutter/test/material/circle_avatar_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ void main() {
146146
expect(paragraph.text.style!.color, equals(foregroundColor));
147147
});
148148

149-
testWidgetsWithLeakTracking('CircleAvatar default colors', (WidgetTester tester) async {
150-
final ThemeData theme = ThemeData(useMaterial3: true);
149+
testWidgetsWithLeakTracking('Material3 - CircleAvatar default colors', (WidgetTester tester) async {
150+
final ThemeData theme = ThemeData();
151151
await tester.pumpWidget(
152152
wrap(
153153
child: Theme(
@@ -286,7 +286,7 @@ void main() {
286286
// support is deprecated and the APIs are removed, these tests
287287
// can be deleted.
288288

289-
testWidgetsWithLeakTracking('CircleAvatar default colors with light theme', (WidgetTester tester) async {
289+
testWidgetsWithLeakTracking('Material2 - CircleAvatar default colors with light theme', (WidgetTester tester) async {
290290
final ThemeData theme = ThemeData(useMaterial3: false, primaryColor: Colors.grey.shade100);
291291
await tester.pumpWidget(
292292
wrap(
@@ -308,7 +308,7 @@ void main() {
308308
expect(paragraph.text.style!.color, equals(theme.primaryTextTheme.titleLarge!.color));
309309
});
310310

311-
testWidgetsWithLeakTracking('CircleAvatar default colors with dark theme', (WidgetTester tester) async {
311+
testWidgetsWithLeakTracking('Material2 - CircleAvatar default colors with dark theme', (WidgetTester tester) async {
312312
final ThemeData theme = ThemeData(useMaterial3: false, primaryColor: Colors.grey.shade800);
313313
await tester.pumpWidget(
314314
wrap(

packages/flutter/test/material/data_table_test.dart

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1651,7 +1651,7 @@ void main() {
16511651
expect(lastTableRowBoxDecoration().color, disabledColor);
16521652
});
16531653

1654-
testWidgetsWithLeakTracking('DataRow renders custom colors when pressed', (WidgetTester tester) async {
1654+
testWidgetsWithLeakTracking('Material2 - DataRow renders custom colors when pressed', (WidgetTester tester) async {
16551655
const Color pressedColor = Color(0xff4caf50);
16561656
Widget buildTable() {
16571657
return DataTable(
@@ -1691,6 +1691,53 @@ void main() {
16911691
await gesture.up();
16921692
});
16931693

1694+
testWidgetsWithLeakTracking('Material3 - DataRow renders custom colors when pressed', (WidgetTester tester) async {
1695+
const Color pressedColor = Color(0xff4caf50);
1696+
Widget buildTable() {
1697+
return DataTable(
1698+
columns: const <DataColumn>[
1699+
DataColumn(
1700+
label: Text('Column1'),
1701+
),
1702+
],
1703+
rows: <DataRow>[
1704+
DataRow(
1705+
color: MaterialStateProperty.resolveWith<Color>(
1706+
(Set<MaterialState> states) {
1707+
if (states.contains(MaterialState.pressed)) {
1708+
return pressedColor;
1709+
}
1710+
return Colors.transparent;
1711+
},
1712+
),
1713+
onSelectChanged: (bool? value) {},
1714+
cells: const <DataCell>[
1715+
DataCell(Text('Content1')),
1716+
],
1717+
),
1718+
],
1719+
);
1720+
}
1721+
1722+
await tester.pumpWidget(MaterialApp(
1723+
theme: ThemeData(),
1724+
home: Material(child: buildTable()),
1725+
));
1726+
1727+
final TestGesture gesture = await tester.startGesture(tester.getCenter(find.text('Content1')));
1728+
await tester.pump(const Duration(milliseconds: 200)); // splash is well underway
1729+
final RenderBox box = Material.of(tester.element(find.byType(InkWell)))as RenderBox;
1730+
// Material 3 uses the InkSparkle which uses a shader, so we can't capture
1731+
// the effect with paint methods.
1732+
expect(
1733+
box,
1734+
paints
1735+
..rect()
1736+
..rect(rect: const Rect.fromLTRB(0.0, 56.0, 800.0, 104.0), color: pressedColor.withOpacity(0.0)),
1737+
);
1738+
await gesture.up();
1739+
});
1740+
16941741
testWidgetsWithLeakTracking('DataTable can render inside an AlertDialog', (WidgetTester tester) async {
16951742
await tester.pumpWidget(
16961743
MaterialApp(

0 commit comments

Comments
 (0)