Skip to content

Commit 0eb2d51

Browse files
authored
Use the new pushImageFilter offset parameter to fix the transform of the children (flutter#113673) (flutter#115884)
1 parent 4edb768 commit 0eb2d51

File tree

3 files changed

+61
-3
lines changed

3 files changed

+61
-3
lines changed

packages/flutter/lib/src/rendering/layer.dart

+3-1
Original file line numberDiff line numberDiff line change
@@ -1816,13 +1816,14 @@ class ColorFilterLayer extends ContainerLayer {
18161816
}
18171817

18181818
/// A composite layer that applies an [ImageFilter] to its children.
1819-
class ImageFilterLayer extends ContainerLayer {
1819+
class ImageFilterLayer extends OffsetLayer {
18201820
/// Creates a layer that applies an [ImageFilter] to its children.
18211821
///
18221822
/// The [imageFilter] property must be non-null before the compositing phase
18231823
/// of the pipeline.
18241824
ImageFilterLayer({
18251825
ui.ImageFilter? imageFilter,
1826+
super.offset,
18261827
}) : _imageFilter = imageFilter;
18271828

18281829
/// The image filter to apply to children.
@@ -1844,6 +1845,7 @@ class ImageFilterLayer extends ContainerLayer {
18441845
assert(imageFilter != null);
18451846
engineLayer = builder.pushImageFilter(
18461847
imageFilter!,
1848+
offset: offset,
18471849
oldLayer: _engineLayer as ui.ImageFilterEngineLayer?,
18481850
);
18491851
addChildrenToScene(builder);

packages/flutter/lib/src/widgets/image_filter.dart

+3-2
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,13 @@ class _ImageFilterRenderObject extends RenderProxyBox {
105105
}
106106

107107
if (layer == null) {
108-
layer = ImageFilterLayer(imageFilter: imageFilter);
108+
layer = ImageFilterLayer(imageFilter: imageFilter, offset: offset);
109109
} else {
110110
final ImageFilterLayer filterLayer = layer! as ImageFilterLayer;
111111
filterLayer.imageFilter = imageFilter;
112+
filterLayer.offset = offset;
112113
}
113-
context.pushLayer(layer!, super.paint, offset);
114+
context.pushLayer(layer!, super.paint, Offset.zero);
114115
assert(() {
115116
layer!.debugCreator = debugCreator;
116117
return true;

packages/flutter/test/widgets/image_filter_test.dart

+55
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// machines.
77
@Tags(<String>['reduced-test-set'])
88

9+
import 'dart:math';
910
import 'dart:ui';
1011

1112
import 'package:flutter/foundation.dart';
@@ -29,6 +30,24 @@ void main() {
2930
);
3031
});
3132

33+
testWidgets('Image filter - blur with offset', (WidgetTester tester) async {
34+
await tester.pumpWidget(
35+
RepaintBoundary(
36+
child: Transform.translate(
37+
offset: const Offset(50, 50),
38+
child: ImageFiltered(
39+
imageFilter: ImageFilter.blur(sigmaX: 3.0, sigmaY: 3.0),
40+
child: const Placeholder(),
41+
),
42+
),
43+
),
44+
);
45+
await expectLater(
46+
find.byType(ImageFiltered),
47+
matchesGoldenFile('image_filter_blur_offset.png'),
48+
);
49+
});
50+
3251
testWidgets('Image filter - dilate', (WidgetTester tester) async {
3352
await tester.pumpWidget(
3453
RepaintBoundary(
@@ -97,6 +116,42 @@ void main() {
97116
);
98117
});
99118

119+
testWidgets('Image filter - matrix with offset', (WidgetTester tester) async {
120+
final Matrix4 matrix = Matrix4.rotationZ(pi / 18);
121+
final ImageFilter matrixFilter = ImageFilter.matrix(matrix.storage);
122+
await tester.pumpWidget(
123+
RepaintBoundary(
124+
child: Transform.translate(
125+
offset: const Offset(50, 50),
126+
child: ImageFiltered(
127+
imageFilter: matrixFilter,
128+
child: MaterialApp(
129+
title: 'Flutter Demo',
130+
theme: ThemeData(primarySwatch: Colors.blue),
131+
home: Scaffold(
132+
appBar: AppBar(
133+
title: const Text('Matrix ImageFilter Test'),
134+
),
135+
body: const Center(
136+
child:Text('Hooray!'),
137+
),
138+
floatingActionButton: FloatingActionButton(
139+
onPressed: () { },
140+
tooltip: 'Increment',
141+
child: const Icon(Icons.add),
142+
),
143+
),
144+
),
145+
),
146+
),
147+
),
148+
);
149+
await expectLater(
150+
find.byType(ImageFiltered),
151+
matchesGoldenFile('image_filter_matrix_offset.png'),
152+
);
153+
});
154+
100155
testWidgets('Image filter - reuses its layer', (WidgetTester tester) async {
101156
Future<void> pumpWithSigma(double sigma) async {
102157
await tester.pumpWidget(

0 commit comments

Comments
 (0)