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 {
/// The [placeholder] and [image] may be composed in a [ResizeImage] to provide
/// 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].
///
/// The [placeholder] and [image] may have their own FilterQuality settings via [filterQuality]
/// and [placeholderFilterQuality].
///
/// The [placeholder], [image], [fadeOutDuration], [fadeOutCurve],
/// [fadeInDuration], [fadeInCurve], [alignment], [repeat], and
/// [matchTextDirection] arguments must not be null.
......@@ -89,6 +92,8 @@ class FadeInImage extends StatefulWidget {
this.height,
this.fit,
this.placeholderFit,
this.filterQuality = FilterQuality.low,
this.placeholderFilterQuality,
this.alignment = Alignment.center,
this.repeat = ImageRepeat.noRepeat,
this.matchTextDirection = false,
......@@ -148,6 +153,8 @@ class FadeInImage extends StatefulWidget {
this.height,
this.fit,
this.placeholderFit,
this.filterQuality = FilterQuality.low,
this.placeholderFilterQuality,
this.alignment = Alignment.center,
this.repeat = ImageRepeat.noRepeat,
this.matchTextDirection = false,
......@@ -219,6 +226,8 @@ class FadeInImage extends StatefulWidget {
this.height,
this.fit,
this.placeholderFit,
this.filterQuality = FilterQuality.low,
this.placeholderFilterQuality,
this.alignment = Alignment.center,
this.repeat = ImageRepeat.noRepeat,
this.matchTextDirection = false,
......@@ -301,6 +310,16 @@ class FadeInImage extends StatefulWidget {
/// If not value set, it will fallback to [fit].
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.
///
/// The alignment aligns the given position in the image to the given position
......@@ -379,6 +398,7 @@ class _FadeInImageState extends State<FadeInImage> {
ImageErrorWidgetBuilder? errorBuilder,
ImageFrameBuilder? frameBuilder,
BoxFit? fit,
required FilterQuality filterQuality,
required Animation<double> opacity,
}) {
assert(image != null);
......@@ -390,6 +410,7 @@ class _FadeInImageState extends State<FadeInImage> {
width: widget.width,
height: widget.height,
fit: fit,
filterQuality: filterQuality,
alignment: widget.alignment,
repeat: widget.repeat,
matchTextDirection: widget.matchTextDirection,
......@@ -405,6 +426,7 @@ class _FadeInImageState extends State<FadeInImage> {
errorBuilder: widget.imageErrorBuilder,
opacity: _imageAnimation,
fit: widget.fit,
filterQuality: widget.filterQuality,
frameBuilder: (BuildContext context, Widget child, int? frame, bool wasSynchronouslyLoaded) {
if (wasSynchronouslyLoaded || frame != null) {
targetLoaded = true;
......@@ -417,6 +439,7 @@ class _FadeInImageState extends State<FadeInImage> {
errorBuilder: widget.placeholderErrorBuilder,
opacity: _placeholderAnimation,
fit: widget.placeholderFit ?? widget.fit,
filterQuality: widget.placeholderFilterQuality ?? widget.filterQuality,
),
placeholderProxyAnimation: _placeholderAnimation,
isTargetLoaded: targetLoaded,
......
......@@ -870,6 +870,7 @@ class Image extends StatefulWidget {
/// 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
/// with the physical screen pixels, extra quality enhancement may not be
/// necessary. If so, then [FilterQuality.none] would be the most efficient.
......@@ -884,6 +885,7 @@ class Image extends StatefulWidget {
///
/// * [FilterQuality], the enum containing all possible filter quality
/// options.
/// {@endtemplate}
final FilterQuality filterQuality;
/// Used to combine [color] with this image.
......
......@@ -52,6 +52,7 @@ class FadeInImageElements {
RawImage get rawImage => rawImageElement.widget as RawImage;
double get opacity => rawImage.opacity?.value ?? 1.0;
BoxFit? get fit => rawImage.fit;
FilterQuality? get filterQuality => rawImage.filterQuality;
}
class LoadTestImageProvider extends ImageProvider<Object> {
......@@ -517,5 +518,36 @@ Future<void> main() async {
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