Skip to content

Commit cca4130

Browse files
authored
Update image_filter_test and color_filter_test.dart for Material 3 (#158985)
Updated unit tests for `ColorFiltered` and `ImageFiltered` to have M2 and M3 versions. More info in #139076 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [ ] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/wiki/Tree-hygiene#overview [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [test-exempt]: https://github.com/flutter/flutter/wiki/Tree-hygiene#tests [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [Features we expect every widget to implement]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat [Data Driven Fixes]: https://github.com/flutter/flutter/wiki/Data-driven-Fixes
1 parent 8509d78 commit cca4130

2 files changed

Lines changed: 125 additions & 11 deletions

File tree

packages/flutter/test/widgets/color_filter_test.dart

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ void main() {
3030
);
3131
});
3232

33-
testWidgets('Color filter - sepia', (WidgetTester tester) async {
34-
33+
testWidgets('Material2 - Color filter - sepia', (WidgetTester tester) async {
3534
const ColorFilter sepia = ColorFilter.matrix(<double>[
3635
0.39, 0.769, 0.189, 0, 0, //
3736
0.349, 0.686, 0.168, 0, 0, //
@@ -65,7 +64,45 @@ void main() {
6564
);
6665
await expectLater(
6766
find.byType(ColorFiltered),
68-
matchesGoldenFile('color_filter_sepia.png'),
67+
matchesGoldenFile('color_filter_sepia_m2.png'),
68+
);
69+
}, skip: impellerEnabled); // https://github.com/flutter/flutter/issues/143616
70+
71+
testWidgets('Color filter - sepia', (WidgetTester tester) async {
72+
const ColorFilter sepia = ColorFilter.matrix(<double>[
73+
0.39, 0.769, 0.189, 0, 0, //
74+
0.349, 0.686, 0.168, 0, 0, //
75+
0.272, 0.534, 0.131, 0, 0, //
76+
0, 0, 0, 1, 0, //
77+
]);
78+
await tester.pumpWidget(
79+
RepaintBoundary(
80+
child: ColorFiltered(
81+
colorFilter: sepia,
82+
child: MaterialApp(
83+
debugShowCheckedModeBanner: false, // https://github.com/flutter/flutter/issues/143616
84+
title: 'Flutter Demo',
85+
theme: ThemeData(colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue)),
86+
home: Scaffold(
87+
appBar: AppBar(
88+
title: const Text('Sepia ColorFilter Test'),
89+
),
90+
body: const Center(
91+
child:Text('Hooray!'),
92+
),
93+
floatingActionButton: FloatingActionButton(
94+
onPressed: () { },
95+
tooltip: 'Increment',
96+
child: const Icon(Icons.add),
97+
),
98+
),
99+
),
100+
),
101+
),
102+
);
103+
await expectLater(
104+
find.byType(ColorFiltered),
105+
matchesGoldenFile('color_filter_sepia_m3.png'),
69106
);
70107
}, skip: impellerEnabled); // https://github.com/flutter/flutter/issues/143616
71108

packages/flutter/test/widgets/image_filter_test.dart

Lines changed: 85 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ void main() {
8282
);
8383
}, skip: kIsWeb); // https://github.com/flutter/flutter/issues/101874
8484

85-
testWidgets('Image filter - matrix', (WidgetTester tester) async {
85+
testWidgets('Material2 - Image filter - matrix', (WidgetTester tester) async {
8686
final ImageFilter matrix = ImageFilter.matrix(Float64List.fromList(<double>[
87-
0.5, 0.0, 0.0, 0.0, //
88-
0.0, 0.5, 0.0, 0.0, //
89-
0.0, 0.0, 1.0, 0.0, //
90-
0.0, 0.0, 0.0, 1.0, //
87+
0.5, 0.0, 0.0, 0.0,
88+
0.0, 0.5, 0.0, 0.0,
89+
0.0, 0.0, 1.0, 0.0,
90+
0.0, 0.0, 0.0, 1.0,
9191
]));
9292
await tester.pumpWidget(
9393
RepaintBoundary(
@@ -116,11 +116,49 @@ void main() {
116116
);
117117
await expectLater(
118118
find.byType(ImageFiltered),
119-
matchesGoldenFile('image_filter_matrix.png'),
119+
matchesGoldenFile('image_filter_matrix_m2.png'),
120120
);
121121
});
122122

123-
testWidgets('Image filter - matrix with offset', (WidgetTester tester) async {
123+
testWidgets('Image filter - matrix', (WidgetTester tester) async {
124+
final ImageFilter matrix = ImageFilter.matrix(Float64List.fromList(<double>[
125+
0.5, 0.0, 0.0, 0.0,
126+
0.0, 0.5, 0.0, 0.0,
127+
0.0, 0.0, 1.0, 0.0,
128+
0.0, 0.0, 0.0, 1.0,
129+
]));
130+
await tester.pumpWidget(
131+
RepaintBoundary(
132+
child: ImageFiltered(
133+
imageFilter: matrix,
134+
child: MaterialApp(
135+
title: 'Flutter Demo',
136+
theme: ThemeData(colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue)),
137+
debugShowCheckedModeBanner: false, // https://github.com/flutter/flutter/issues/143616
138+
home: Scaffold(
139+
appBar: AppBar(
140+
title: const Text('Matrix ImageFilter Test'),
141+
),
142+
body: const Center(
143+
child:Text('Hooray!'),
144+
),
145+
floatingActionButton: FloatingActionButton(
146+
onPressed: () { },
147+
tooltip: 'Increment',
148+
child: const Icon(Icons.add),
149+
),
150+
),
151+
),
152+
),
153+
),
154+
);
155+
await expectLater(
156+
find.byType(ImageFiltered),
157+
matchesGoldenFile('image_filter_matrix_m3.png'),
158+
);
159+
});
160+
161+
testWidgets('Material2 - Image filter - matrix with offset', (WidgetTester tester) async {
124162
final Matrix4 matrix = Matrix4.rotationZ(pi / 18);
125163
final ImageFilter matrixFilter = ImageFilter.matrix(matrix.storage);
126164
final Key key = GlobalKey();
@@ -155,7 +193,46 @@ void main() {
155193
);
156194
await expectLater(
157195
find.byKey(key),
158-
matchesGoldenFile('image_filter_matrix_offset.png'),
196+
matchesGoldenFile('image_filter_matrix_offset_m2.png'),
197+
);
198+
});
199+
200+
testWidgets('Image filter - matrix with offset', (WidgetTester tester) async {
201+
final Matrix4 matrix = Matrix4.rotationZ(pi / 18);
202+
final ImageFilter matrixFilter = ImageFilter.matrix(matrix.storage);
203+
final Key key = GlobalKey();
204+
await tester.pumpWidget(
205+
RepaintBoundary(
206+
key: key,
207+
child: Transform.translate(
208+
offset: const Offset(50, 50),
209+
child: ImageFiltered(
210+
imageFilter: matrixFilter,
211+
child: MaterialApp(
212+
title: 'Flutter Demo',
213+
theme: ThemeData(colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue)),
214+
debugShowCheckedModeBanner: false, // https://github.com/flutter/flutter/issues/143616
215+
home: Scaffold(
216+
appBar: AppBar(
217+
title: const Text('Matrix ImageFilter Test'),
218+
),
219+
body: const Center(
220+
child:Text('Hooray!'),
221+
),
222+
floatingActionButton: FloatingActionButton(
223+
onPressed: () { },
224+
tooltip: 'Increment',
225+
child: const Icon(Icons.add),
226+
),
227+
),
228+
),
229+
),
230+
),
231+
),
232+
);
233+
await expectLater(
234+
find.byKey(key),
235+
matchesGoldenFile('image_filter_matrix_offset_m3.png'),
159236
);
160237
});
161238

0 commit comments

Comments
 (0)