Unverified Commit 50ead38f authored by Tuyen VU's avatar Tuyen VU Committed by GitHub

- add FadeInImage.placeholderFit (#90739)

parent ebb48e16
...@@ -67,6 +67,9 @@ class FadeInImage extends StatefulWidget { ...@@ -67,6 +67,9 @@ 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]
/// and [placeholderFit].
///
/// 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.
...@@ -87,6 +90,7 @@ class FadeInImage extends StatefulWidget { ...@@ -87,6 +90,7 @@ class FadeInImage extends StatefulWidget {
this.width, this.width,
this.height, this.height,
this.fit, this.fit,
this.placeholderFit,
this.alignment = Alignment.center, this.alignment = Alignment.center,
this.repeat = ImageRepeat.noRepeat, this.repeat = ImageRepeat.noRepeat,
this.matchTextDirection = false, this.matchTextDirection = false,
...@@ -146,6 +150,7 @@ class FadeInImage extends StatefulWidget { ...@@ -146,6 +150,7 @@ class FadeInImage extends StatefulWidget {
this.width, this.width,
this.height, this.height,
this.fit, this.fit,
this.placeholderFit,
this.alignment = Alignment.center, this.alignment = Alignment.center,
this.repeat = ImageRepeat.noRepeat, this.repeat = ImageRepeat.noRepeat,
this.matchTextDirection = false, this.matchTextDirection = false,
...@@ -217,6 +222,7 @@ class FadeInImage extends StatefulWidget { ...@@ -217,6 +222,7 @@ class FadeInImage extends StatefulWidget {
this.width, this.width,
this.height, this.height,
this.fit, this.fit,
this.placeholderFit,
this.alignment = Alignment.center, this.alignment = Alignment.center,
this.repeat = ImageRepeat.noRepeat, this.repeat = ImageRepeat.noRepeat,
this.matchTextDirection = false, this.matchTextDirection = false,
...@@ -295,6 +301,11 @@ class FadeInImage extends StatefulWidget { ...@@ -295,6 +301,11 @@ class FadeInImage extends StatefulWidget {
/// [paintImage]. /// [paintImage].
final BoxFit? fit; final BoxFit? fit;
/// How to inscribe the placeholder image into the space allocated during layout.
///
/// If not value set, it will fallback to [fit].
final BoxFit? placeholderFit;
/// 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
...@@ -376,6 +387,7 @@ class _FadeInImageState extends State<FadeInImage> { ...@@ -376,6 +387,7 @@ class _FadeInImageState extends State<FadeInImage> {
required ImageProvider image, required ImageProvider image,
ImageErrorWidgetBuilder? errorBuilder, ImageErrorWidgetBuilder? errorBuilder,
ImageFrameBuilder? frameBuilder, ImageFrameBuilder? frameBuilder,
BoxFit? fit,
required Animation<double> opacity, required Animation<double> opacity,
}) { }) {
assert(image != null); assert(image != null);
...@@ -386,7 +398,7 @@ class _FadeInImageState extends State<FadeInImage> { ...@@ -386,7 +398,7 @@ class _FadeInImageState extends State<FadeInImage> {
opacity: opacity, opacity: opacity,
width: widget.width, width: widget.width,
height: widget.height, height: widget.height,
fit: widget.fit, fit: fit,
alignment: widget.alignment, alignment: widget.alignment,
repeat: widget.repeat, repeat: widget.repeat,
matchTextDirection: widget.matchTextDirection, matchTextDirection: widget.matchTextDirection,
...@@ -401,6 +413,7 @@ class _FadeInImageState extends State<FadeInImage> { ...@@ -401,6 +413,7 @@ class _FadeInImageState extends State<FadeInImage> {
image: widget.image, image: widget.image,
errorBuilder: widget.imageErrorBuilder, errorBuilder: widget.imageErrorBuilder,
opacity: _imageAnimation, opacity: _imageAnimation,
fit: widget.fit,
frameBuilder: (BuildContext context, Widget child, int? frame, bool wasSynchronouslyLoaded) { frameBuilder: (BuildContext context, Widget child, int? frame, bool wasSynchronouslyLoaded) {
if (wasSynchronouslyLoaded) { if (wasSynchronouslyLoaded) {
_resetAnimations(); _resetAnimations();
...@@ -413,6 +426,7 @@ class _FadeInImageState extends State<FadeInImage> { ...@@ -413,6 +426,7 @@ class _FadeInImageState extends State<FadeInImage> {
image: widget.placeholder, image: widget.placeholder,
errorBuilder: widget.placeholderErrorBuilder, errorBuilder: widget.placeholderErrorBuilder,
opacity: _placeholderAnimation, opacity: _placeholderAnimation,
fit: widget.placeholderFit ?? widget.fit,
), ),
placeholderProxyAnimation: _placeholderAnimation, placeholderProxyAnimation: _placeholderAnimation,
isTargetLoaded: frame != null, isTargetLoaded: frame != null,
......
...@@ -49,6 +49,7 @@ class FadeInImageElements { ...@@ -49,6 +49,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;
} }
class LoadTestImageProvider extends ImageProvider<Object> { class LoadTestImageProvider extends ImageProvider<Object> {
...@@ -435,5 +436,36 @@ Future<void> main() async { ...@@ -435,5 +436,36 @@ Future<void> main() async {
}); });
}); });
}); });
group("placeholder's BoxFit", () {
testWidgets("should be the image's BoxFit when not set", (WidgetTester tester) async {
final TestImageProvider placeholderProvider = TestImageProvider(placeholderImage);
final TestImageProvider imageProvider = TestImageProvider(targetImage);
await tester.pumpWidget(FadeInImage(
placeholder: placeholderProvider,
image: imageProvider,
fit: BoxFit.cover,
));
expect(findFadeInImage(tester).placeholder!.fit, equals(findFadeInImage(tester).target.fit));
expect(findFadeInImage(tester).placeholder!.fit, equals(BoxFit.cover));
});
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,
fit: BoxFit.cover,
placeholderFit: BoxFit.fill,
));
expect(findFadeInImage(tester).target.fit, equals(BoxFit.cover));
expect(findFadeInImage(tester).placeholder!.fit, equals(BoxFit.fill));
});
});
}); });
} }
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