Skip to content

Commit 8bed1cb

Browse files
authored
Switch to FilterQuality.medium for images (#148799)
flutter/flutter#148253
1 parent 1658e2a commit 8bed1cb

12 files changed

+29
-35
lines changed

packages/flutter/lib/src/material/page_transitions_theme.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ void _drawImageScaledAndCentered(PaintingContext context, ui.Image image, double
918918
return;
919919
}
920920
final Paint paint = Paint()
921-
..filterQuality = ui.FilterQuality.low
921+
..filterQuality = ui.FilterQuality.medium
922922
..color = Color.fromRGBO(0, 0, 0, opacity);
923923
final double logicalWidth = image.width / pixelRatio;
924924
final double logicalHeight = image.height / pixelRatio;
@@ -1267,7 +1267,7 @@ class _ZoomEnterTransitionNoCache extends StatelessWidget {
12671267
opacity: fadeTransition,
12681268
child: ScaleTransition(
12691269
scale: scaleTransition,
1270-
filterQuality: FilterQuality.none,
1270+
filterQuality: FilterQuality.medium,
12711271
child: child,
12721272
),
12731273
),
@@ -1300,7 +1300,7 @@ class _ZoomExitTransitionNoCache extends StatelessWidget {
13001300
opacity: fadeTransition,
13011301
child: ScaleTransition(
13021302
scale: scaleTransition,
1303-
filterQuality: FilterQuality.none,
1303+
filterQuality: FilterQuality.medium,
13041304
child: child,
13051305
),
13061306
);

packages/flutter/lib/src/painting/decoration_image.dart

+4-7
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class DecorationImage {
5151
this.matchTextDirection = false,
5252
this.scale = 1.0,
5353
this.opacity = 1.0,
54-
this.filterQuality = FilterQuality.low,
54+
this.filterQuality = FilterQuality.medium,
5555
this.invertColors = false,
5656
this.isAntiAlias = false,
5757
});
@@ -148,8 +148,7 @@ class DecorationImage {
148148

149149
/// Used to set the filterQuality of the image.
150150
///
151-
/// Defaults to [FilterQuality.low] to scale the image, which corresponds to
152-
/// bilinear interpolation.
151+
/// Defaults to [FilterQuality.medium].
153152
final FilterQuality filterQuality;
154153

155154
/// Whether the colors of the image are inverted when drawn.
@@ -508,9 +507,7 @@ void debugFlushLastFrameImageSizeInfo() {
508507
/// smart invert on iOS.
509508
///
510509
/// * `filterQuality`: Use this to change the quality when scaling an image.
511-
/// Use the [FilterQuality.low] quality setting to scale the image, which corresponds to
512-
/// bilinear interpolation, rather than the default [FilterQuality.none] which corresponds
513-
/// to nearest-neighbor.
510+
/// Defaults to [FilterQuality.medium].
514511
///
515512
/// See also:
516513
///
@@ -531,7 +528,7 @@ void paintImage({
531528
ImageRepeat repeat = ImageRepeat.noRepeat,
532529
bool flipHorizontally = false,
533530
bool invertColors = false,
534-
FilterQuality filterQuality = FilterQuality.low,
531+
FilterQuality filterQuality = FilterQuality.medium,
535532
bool isAntiAlias = false,
536533
BlendMode blendMode = BlendMode.srcOver,
537534
}) {

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

+2-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class RenderImage extends RenderBox {
4343
TextDirection? textDirection,
4444
bool invertColors = false,
4545
bool isAntiAlias = false,
46-
FilterQuality filterQuality = FilterQuality.low,
46+
FilterQuality filterQuality = FilterQuality.medium,
4747
}) : _image = image,
4848
_width = width,
4949
_height = height,
@@ -188,9 +188,7 @@ class RenderImage extends RenderBox {
188188

189189
/// Used to set the filterQuality of the image.
190190
///
191-
/// Use the [FilterQuality.low] quality setting to scale the image, which corresponds to
192-
/// bilinear interpolation, rather than the default [FilterQuality.none] which corresponds
193-
/// to nearest-neighbor.
191+
/// Defaults to [FilterQuality.medium].
194192
FilterQuality get filterQuality => _filterQuality;
195193
FilterQuality _filterQuality;
196194
set filterQuality(FilterQuality value) {

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -5959,7 +5959,7 @@ class RawImage extends LeafRenderObjectWidget {
59595959
this.centerSlice,
59605960
this.matchTextDirection = false,
59615961
this.invertColors = false,
5962-
this.filterQuality = FilterQuality.low,
5962+
this.filterQuality = FilterQuality.medium,
59635963
this.isAntiAlias = false,
59645964
});
59655965

@@ -6002,8 +6002,7 @@ class RawImage extends LeafRenderObjectWidget {
60026002

60036003
/// Used to set the filterQuality of the image.
60046004
///
6005-
/// Defaults to [FilterQuality.low] to scale the image, which corresponds to
6006-
/// bilinear interpolation.
6005+
/// Defaults to [FilterQuality.medium].
60076006
final FilterQuality filterQuality;
60086007

60096008
/// Used to combine [color] with this image.

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class FadeInImage extends StatefulWidget {
9292
this.height,
9393
this.fit,
9494
this.placeholderFit,
95-
this.filterQuality = FilterQuality.low,
95+
this.filterQuality = FilterQuality.medium,
9696
this.placeholderFilterQuality,
9797
this.alignment = Alignment.center,
9898
this.repeat = ImageRepeat.noRepeat,
@@ -149,7 +149,7 @@ class FadeInImage extends StatefulWidget {
149149
this.placeholderColor,
150150
this.placeholderColorBlendMode,
151151
this.placeholderFit,
152-
this.filterQuality = FilterQuality.low,
152+
this.filterQuality = FilterQuality.medium,
153153
this.placeholderFilterQuality,
154154
this.alignment = Alignment.center,
155155
this.repeat = ImageRepeat.noRepeat,
@@ -211,7 +211,7 @@ class FadeInImage extends StatefulWidget {
211211
this.placeholderColor,
212212
this.placeholderColorBlendMode,
213213
this.placeholderFit,
214-
this.filterQuality = FilterQuality.low,
214+
this.filterQuality = FilterQuality.medium,
215215
this.placeholderFilterQuality,
216216
this.alignment = Alignment.center,
217217
this.repeat = ImageRepeat.noRepeat,

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

+7-5
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ class Image extends StatefulWidget {
366366
this.matchTextDirection = false,
367367
this.gaplessPlayback = false,
368368
this.isAntiAlias = false,
369-
this.filterQuality = FilterQuality.low,
369+
this.filterQuality = FilterQuality.medium,
370370
});
371371

372372
/// Creates a widget that displays an [ImageStream] obtained from the network.
@@ -414,7 +414,7 @@ class Image extends StatefulWidget {
414414
this.centerSlice,
415415
this.matchTextDirection = false,
416416
this.gaplessPlayback = false,
417-
this.filterQuality = FilterQuality.low,
417+
this.filterQuality = FilterQuality.medium,
418418
this.isAntiAlias = false,
419419
Map<String, String>? headers,
420420
int? cacheWidth,
@@ -471,7 +471,7 @@ class Image extends StatefulWidget {
471471
this.matchTextDirection = false,
472472
this.gaplessPlayback = false,
473473
this.isAntiAlias = false,
474-
this.filterQuality = FilterQuality.low,
474+
this.filterQuality = FilterQuality.medium,
475475
int? cacheWidth,
476476
int? cacheHeight,
477477
}) :
@@ -631,7 +631,7 @@ class Image extends StatefulWidget {
631631
this.gaplessPlayback = false,
632632
this.isAntiAlias = false,
633633
String? package,
634-
this.filterQuality = FilterQuality.low,
634+
this.filterQuality = FilterQuality.medium,
635635
int? cacheWidth,
636636
int? cacheHeight,
637637
}) : image = ResizeImage.resizeIfNeeded(
@@ -693,7 +693,7 @@ class Image extends StatefulWidget {
693693
this.matchTextDirection = false,
694694
this.gaplessPlayback = false,
695695
this.isAntiAlias = false,
696-
this.filterQuality = FilterQuality.low,
696+
this.filterQuality = FilterQuality.medium,
697697
int? cacheWidth,
698698
int? cacheHeight,
699699
}) : image = ResizeImage.resizeIfNeeded(cacheWidth, cacheHeight, MemoryImage(bytes, scale: scale)),
@@ -873,6 +873,8 @@ class Image extends StatefulWidget {
873873
/// improve the rendered image quality in this case. Pixels may be misaligned
874874
/// with the screen pixels as a result of transforms or scaling.
875875
///
876+
/// Defaults to [FilterQuality.medium].
877+
///
876878
/// See also:
877879
///
878880
/// * [FilterQuality], the enum containing all possible filter quality

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ class _StretchingOverscrollIndicatorState extends State<StretchingOverscrollIndi
777777
final Widget transform = Transform(
778778
alignment: alignment,
779779
transform: Matrix4.diagonal3Values(x, y, 1.0),
780-
filterQuality: stretch == 0 ? null : FilterQuality.low,
780+
filterQuality: stretch == 0 ? null : FilterQuality.medium,
781781
child: widget.child,
782782
);
783783

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ class _RenderSnapshotWidget extends RenderProxyBox {
381381
/// final Rect src = Rect.fromLTWH(0, 0, image.width.toDouble(), image.height.toDouble());
382382
/// final Rect dst = Rect.fromLTWH(offset.dx, offset.dy, size.width, size.height);
383383
/// final Paint paint = Paint()
384-
/// ..filterQuality = FilterQuality.low;
384+
/// ..filterQuality = FilterQuality.medium;
385385
/// context.canvas.drawImageRect(image, src, dst, paint);
386386
/// }
387387
/// ```
@@ -414,7 +414,7 @@ abstract class SnapshotPainter extends ChangeNotifier {
414414
/// final Rect src = Rect.fromLTWH(0, 0, sourceSize.width, sourceSize.height);
415415
/// final Rect dst = Rect.fromLTWH(offset.dx, offset.dy, size.width, size.height);
416416
/// final Paint paint = Paint()
417-
/// ..filterQuality = FilterQuality.low;
417+
/// ..filterQuality = FilterQuality.medium;
418418
/// context.canvas.drawImageRect(image, src, dst, paint);
419419
/// }
420420
/// ```
@@ -482,7 +482,7 @@ class _DefaultSnapshotPainter implements SnapshotPainter {
482482
final Rect src = Rect.fromLTWH(0, 0, sourceSize.width, sourceSize.height);
483483
final Rect dst = Rect.fromLTWH(offset.dx, offset.dy, size.width, size.height);
484484
final Paint paint = Paint()
485-
..filterQuality = FilterQuality.low;
485+
..filterQuality = FilterQuality.medium;
486486
context.canvas.drawImageRect(image, src, dst, paint);
487487
}
488488

packages/flutter/test/painting/decoration_test.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ void main() {
341341
opacity: 0.99,
342342
scale: 2.01,
343343
).toString(),
344-
'DecorationImage(SynchronousTestImageProvider(), Alignment.center, scale 2.0, opacity 1.0, FilterQuality.low)',
344+
'DecorationImage(SynchronousTestImageProvider(), Alignment.center, scale 2.0, opacity 1.0, FilterQuality.medium)',
345345
);
346346
});
347347

@@ -389,7 +389,7 @@ void main() {
389389
' BoxFit.contain, Alignment.center, centerSlice:\n'
390390
' Rect.fromLTRB(10.0, 20.0, 40.0, 60.0), ImageRepeat.repeatY,\n'
391391
' match text direction, scale 0.5, opacity 0.5,\n'
392-
' FilterQuality.low, invert colors, use anti-aliasing)\n'
392+
' FilterQuality.medium, invert colors, use anti-aliasing)\n'
393393
' The ImageConfiguration was:\n'
394394
' ImageConfiguration(size: Size(100.0, 100.0))\n',
395395
);

packages/flutter/test/rendering/image_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Future<void> main() async {
4040
' image: $squareImage\n'
4141
' alignment: Alignment.center\n'
4242
' invertColors: false\n'
43-
' filterQuality: low\n',
43+
' filterQuality: medium\n',
4444
),
4545
);
4646

packages/flutter/test/widgets/basic_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void main() {
4747
expect(renderObject.centerSlice, null);
4848
expect(renderObject.matchTextDirection, false);
4949
expect(renderObject.invertColors, false);
50-
expect(renderObject.filterQuality, FilterQuality.low);
50+
expect(renderObject.filterQuality, FilterQuality.medium);
5151
expect(renderObject.isAntiAlias, false);
5252

5353
final ui.Image image2 = (await tester.runAsync<ui.Image>(() => createTestImage(width: 2, height: 2)))!;

packages/flutter/test/widgets/fade_in_image_test.dart

-2
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,6 @@ void main() {
590590
await tester.pumpWidget(FadeInImage(
591591
placeholder: placeholderProvider,
592592
image: imageProvider,
593-
filterQuality: FilterQuality.medium,
594593
));
595594

596595
expect(findFadeInImage(tester).placeholder!.filterQuality, equals(findFadeInImage(tester).target.filterQuality));
@@ -604,7 +603,6 @@ void main() {
604603
await tester.pumpWidget(FadeInImage(
605604
placeholder: placeholderProvider,
606605
image: imageProvider,
607-
filterQuality: FilterQuality.medium,
608606
placeholderFilterQuality: FilterQuality.high,
609607
));
610608

0 commit comments

Comments
 (0)