- add FadeInImage.placeholderFit (#90739)
This commit is contained in:
parent
ebb48e1650
commit
50ead38f2f
@ -67,6 +67,9 @@ 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]
|
||||
/// and [placeholderFit].
|
||||
///
|
||||
/// The [placeholder], [image], [fadeOutDuration], [fadeOutCurve],
|
||||
/// [fadeInDuration], [fadeInCurve], [alignment], [repeat], and
|
||||
/// [matchTextDirection] arguments must not be null.
|
||||
@ -87,6 +90,7 @@ class FadeInImage extends StatefulWidget {
|
||||
this.width,
|
||||
this.height,
|
||||
this.fit,
|
||||
this.placeholderFit,
|
||||
this.alignment = Alignment.center,
|
||||
this.repeat = ImageRepeat.noRepeat,
|
||||
this.matchTextDirection = false,
|
||||
@ -146,6 +150,7 @@ class FadeInImage extends StatefulWidget {
|
||||
this.width,
|
||||
this.height,
|
||||
this.fit,
|
||||
this.placeholderFit,
|
||||
this.alignment = Alignment.center,
|
||||
this.repeat = ImageRepeat.noRepeat,
|
||||
this.matchTextDirection = false,
|
||||
@ -217,6 +222,7 @@ class FadeInImage extends StatefulWidget {
|
||||
this.width,
|
||||
this.height,
|
||||
this.fit,
|
||||
this.placeholderFit,
|
||||
this.alignment = Alignment.center,
|
||||
this.repeat = ImageRepeat.noRepeat,
|
||||
this.matchTextDirection = false,
|
||||
@ -295,6 +301,11 @@ class FadeInImage extends StatefulWidget {
|
||||
/// [paintImage].
|
||||
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.
|
||||
///
|
||||
/// The alignment aligns the given position in the image to the given position
|
||||
@ -376,6 +387,7 @@ class _FadeInImageState extends State<FadeInImage> {
|
||||
required ImageProvider image,
|
||||
ImageErrorWidgetBuilder? errorBuilder,
|
||||
ImageFrameBuilder? frameBuilder,
|
||||
BoxFit? fit,
|
||||
required Animation<double> opacity,
|
||||
}) {
|
||||
assert(image != null);
|
||||
@ -386,7 +398,7 @@ class _FadeInImageState extends State<FadeInImage> {
|
||||
opacity: opacity,
|
||||
width: widget.width,
|
||||
height: widget.height,
|
||||
fit: widget.fit,
|
||||
fit: fit,
|
||||
alignment: widget.alignment,
|
||||
repeat: widget.repeat,
|
||||
matchTextDirection: widget.matchTextDirection,
|
||||
@ -401,6 +413,7 @@ class _FadeInImageState extends State<FadeInImage> {
|
||||
image: widget.image,
|
||||
errorBuilder: widget.imageErrorBuilder,
|
||||
opacity: _imageAnimation,
|
||||
fit: widget.fit,
|
||||
frameBuilder: (BuildContext context, Widget child, int? frame, bool wasSynchronouslyLoaded) {
|
||||
if (wasSynchronouslyLoaded) {
|
||||
_resetAnimations();
|
||||
@ -413,6 +426,7 @@ class _FadeInImageState extends State<FadeInImage> {
|
||||
image: widget.placeholder,
|
||||
errorBuilder: widget.placeholderErrorBuilder,
|
||||
opacity: _placeholderAnimation,
|
||||
fit: widget.placeholderFit ?? widget.fit,
|
||||
),
|
||||
placeholderProxyAnimation: _placeholderAnimation,
|
||||
isTargetLoaded: frame != null,
|
||||
|
@ -49,6 +49,7 @@ class FadeInImageElements {
|
||||
|
||||
RawImage get rawImage => rawImageElement.widget as RawImage;
|
||||
double get opacity => rawImage.opacity?.value ?? 1.0;
|
||||
BoxFit? get fit => rawImage.fit;
|
||||
}
|
||||
|
||||
class LoadTestImageProvider extends ImageProvider<Object> {
|
||||
@ -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));
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user