Unverified Commit c5edf629 authored by FluentCoding's avatar FluentCoding Committed by GitHub

Support for FilterQuality in FadeInImage (#110096)

parent d88376ae
...@@ -65,9 +65,12 @@ class FadeInImage extends StatefulWidget { ...@@ -65,9 +65,12 @@ class FadeInImage extends StatefulWidget {
/// The [placeholder] and [image] may be composed in a [ResizeImage] to provide /// The [placeholder] and [image] may be composed in a [ResizeImage] to provide
/// a custom decode/cache size. /// a custom decode/cache size.
/// ///
/// The [placeholder] and [image] may be have their own BoxFit settings via [fit] /// The [placeholder] and [image] may have their own BoxFit settings via [fit]
/// and [placeholderFit]. /// and [placeholderFit].
/// ///
/// The [placeholder] and [image] may have their own FilterQuality settings via [filterQuality]
/// and [placeholderFilterQuality].
///
/// The [placeholder], [image], [fadeOutDuration], [fadeOutCurve], /// The [placeholder], [image], [fadeOutDuration], [fadeOutCurve],
/// [fadeInDuration], [fadeInCurve], [alignment], [repeat], and /// [fadeInDuration], [fadeInCurve], [alignment], [repeat], and
/// [matchTextDirection] arguments must not be null. /// [matchTextDirection] arguments must not be null.
...@@ -89,6 +92,8 @@ class FadeInImage extends StatefulWidget { ...@@ -89,6 +92,8 @@ class FadeInImage extends StatefulWidget {
this.height, this.height,
this.fit, this.fit,
this.placeholderFit, this.placeholderFit,
this.filterQuality = FilterQuality.low,
this.placeholderFilterQuality,
this.alignment = Alignment.center, this.alignment = Alignment.center,
this.repeat = ImageRepeat.noRepeat, this.repeat = ImageRepeat.noRepeat,
this.matchTextDirection = false, this.matchTextDirection = false,
...@@ -148,6 +153,8 @@ class FadeInImage extends StatefulWidget { ...@@ -148,6 +153,8 @@ class FadeInImage extends StatefulWidget {
this.height, this.height,
this.fit, this.fit,
this.placeholderFit, this.placeholderFit,
this.filterQuality = FilterQuality.low,
this.placeholderFilterQuality,
this.alignment = Alignment.center, this.alignment = Alignment.center,
this.repeat = ImageRepeat.noRepeat, this.repeat = ImageRepeat.noRepeat,
this.matchTextDirection = false, this.matchTextDirection = false,
...@@ -219,6 +226,8 @@ class FadeInImage extends StatefulWidget { ...@@ -219,6 +226,8 @@ class FadeInImage extends StatefulWidget {
this.height, this.height,
this.fit, this.fit,
this.placeholderFit, this.placeholderFit,
this.filterQuality = FilterQuality.low,
this.placeholderFilterQuality,
this.alignment = Alignment.center, this.alignment = Alignment.center,
this.repeat = ImageRepeat.noRepeat, this.repeat = ImageRepeat.noRepeat,
this.matchTextDirection = false, this.matchTextDirection = false,
...@@ -301,6 +310,16 @@ class FadeInImage extends StatefulWidget { ...@@ -301,6 +310,16 @@ class FadeInImage extends StatefulWidget {
/// If not value set, it will fallback to [fit]. /// If not value set, it will fallback to [fit].
final BoxFit? placeholderFit; final BoxFit? placeholderFit;
/// The rendering quality of the image.
///
/// {@macro flutter.widgets.image.filterQuality}
final FilterQuality filterQuality;
/// The rendering quality of the placeholder image.
///
/// {@macro flutter.widgets.image.filterQuality}
final FilterQuality? placeholderFilterQuality;
/// How to align the image within its bounds. /// How to align the image within its bounds.
/// ///
/// The alignment aligns the given position in the image to the given position /// The alignment aligns the given position in the image to the given position
...@@ -379,6 +398,7 @@ class _FadeInImageState extends State<FadeInImage> { ...@@ -379,6 +398,7 @@ class _FadeInImageState extends State<FadeInImage> {
ImageErrorWidgetBuilder? errorBuilder, ImageErrorWidgetBuilder? errorBuilder,
ImageFrameBuilder? frameBuilder, ImageFrameBuilder? frameBuilder,
BoxFit? fit, BoxFit? fit,
required FilterQuality filterQuality,
required Animation<double> opacity, required Animation<double> opacity,
}) { }) {
assert(image != null); assert(image != null);
...@@ -390,6 +410,7 @@ class _FadeInImageState extends State<FadeInImage> { ...@@ -390,6 +410,7 @@ class _FadeInImageState extends State<FadeInImage> {
width: widget.width, width: widget.width,
height: widget.height, height: widget.height,
fit: fit, fit: fit,
filterQuality: filterQuality,
alignment: widget.alignment, alignment: widget.alignment,
repeat: widget.repeat, repeat: widget.repeat,
matchTextDirection: widget.matchTextDirection, matchTextDirection: widget.matchTextDirection,
...@@ -405,6 +426,7 @@ class _FadeInImageState extends State<FadeInImage> { ...@@ -405,6 +426,7 @@ class _FadeInImageState extends State<FadeInImage> {
errorBuilder: widget.imageErrorBuilder, errorBuilder: widget.imageErrorBuilder,
opacity: _imageAnimation, opacity: _imageAnimation,
fit: widget.fit, fit: widget.fit,
filterQuality: widget.filterQuality,
frameBuilder: (BuildContext context, Widget child, int? frame, bool wasSynchronouslyLoaded) { frameBuilder: (BuildContext context, Widget child, int? frame, bool wasSynchronouslyLoaded) {
if (wasSynchronouslyLoaded || frame != null) { if (wasSynchronouslyLoaded || frame != null) {
targetLoaded = true; targetLoaded = true;
...@@ -417,6 +439,7 @@ class _FadeInImageState extends State<FadeInImage> { ...@@ -417,6 +439,7 @@ class _FadeInImageState extends State<FadeInImage> {
errorBuilder: widget.placeholderErrorBuilder, errorBuilder: widget.placeholderErrorBuilder,
opacity: _placeholderAnimation, opacity: _placeholderAnimation,
fit: widget.placeholderFit ?? widget.fit, fit: widget.placeholderFit ?? widget.fit,
filterQuality: widget.placeholderFilterQuality ?? widget.filterQuality,
), ),
placeholderProxyAnimation: _placeholderAnimation, placeholderProxyAnimation: _placeholderAnimation,
isTargetLoaded: targetLoaded, isTargetLoaded: targetLoaded,
......
...@@ -870,6 +870,7 @@ class Image extends StatefulWidget { ...@@ -870,6 +870,7 @@ class Image extends StatefulWidget {
/// The rendering quality of the image. /// The rendering quality of the image.
/// ///
/// {@template flutter.widgets.image.filterQuality}
/// If the image is of a high quality and its pixels are perfectly aligned /// If the image is of a high quality and its pixels are perfectly aligned
/// with the physical screen pixels, extra quality enhancement may not be /// with the physical screen pixels, extra quality enhancement may not be
/// necessary. If so, then [FilterQuality.none] would be the most efficient. /// necessary. If so, then [FilterQuality.none] would be the most efficient.
...@@ -884,6 +885,7 @@ class Image extends StatefulWidget { ...@@ -884,6 +885,7 @@ class Image extends StatefulWidget {
/// ///
/// * [FilterQuality], the enum containing all possible filter quality /// * [FilterQuality], the enum containing all possible filter quality
/// options. /// options.
/// {@endtemplate}
final FilterQuality filterQuality; final FilterQuality filterQuality;
/// Used to combine [color] with this image. /// Used to combine [color] with this image.
......
...@@ -52,6 +52,7 @@ class FadeInImageElements { ...@@ -52,6 +52,7 @@ class FadeInImageElements {
RawImage get rawImage => rawImageElement.widget as RawImage; RawImage get rawImage => rawImageElement.widget as RawImage;
double get opacity => rawImage.opacity?.value ?? 1.0; double get opacity => rawImage.opacity?.value ?? 1.0;
BoxFit? get fit => rawImage.fit; BoxFit? get fit => rawImage.fit;
FilterQuality? get filterQuality => rawImage.filterQuality;
} }
class LoadTestImageProvider extends ImageProvider<Object> { class LoadTestImageProvider extends ImageProvider<Object> {
...@@ -517,5 +518,36 @@ Future<void> main() async { ...@@ -517,5 +518,36 @@ Future<void> main() async {
expect(findFadeInImage(tester).placeholder!.fit, equals(BoxFit.fill)); expect(findFadeInImage(tester).placeholder!.fit, equals(BoxFit.fill));
}); });
}); });
group("placeholder's FilterQuality", () {
testWidgets("should be the image's FilterQuality when not set", (WidgetTester tester) async {
final TestImageProvider placeholderProvider = TestImageProvider(placeholderImage);
final TestImageProvider imageProvider = TestImageProvider(targetImage);
await tester.pumpWidget(FadeInImage(
placeholder: placeholderProvider,
image: imageProvider,
filterQuality: FilterQuality.medium,
));
expect(findFadeInImage(tester).placeholder!.filterQuality, equals(findFadeInImage(tester).target.filterQuality));
expect(findFadeInImage(tester).placeholder!.filterQuality, equals(FilterQuality.medium));
});
testWidgets('should be the given value when set', (WidgetTester tester) async {
final TestImageProvider placeholderProvider = TestImageProvider(placeholderImage);
final TestImageProvider imageProvider = TestImageProvider(targetImage);
await tester.pumpWidget(FadeInImage(
placeholder: placeholderProvider,
image: imageProvider,
filterQuality: FilterQuality.medium,
placeholderFilterQuality: FilterQuality.high,
));
expect(findFadeInImage(tester).target.filterQuality, equals(FilterQuality.medium));
expect(findFadeInImage(tester).placeholder!.filterQuality, equals(FilterQuality.high));
});
});
}); });
} }
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