mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Fix clipping in FittedBox (#15418)
Fixes https://github.com/flutter/flutter/issues/15410
This commit is contained in:
parent
6758b55c8d
commit
42e4e16b47
@ -2187,7 +2187,7 @@ class RenderFittedBox extends RenderProxyBox {
|
||||
final double scaleY = sizes.destination.height / sizes.source.height;
|
||||
final Rect sourceRect = _resolvedAlignment.inscribe(sizes.source, Offset.zero & childSize);
|
||||
final Rect destinationRect = _resolvedAlignment.inscribe(sizes.destination, Offset.zero & size);
|
||||
_hasVisualOverflow = sourceRect.width < childSize.width || sourceRect.height < childSize.width;
|
||||
_hasVisualOverflow = sourceRect.width < childSize.width || sourceRect.height < childSize.height;
|
||||
_transform = new Matrix4.translationValues(destinationRect.left, destinationRect.top, 0.0)
|
||||
..scale(scaleX, scaleY, 1.0)
|
||||
..translate(-sourceRect.left, -sourceRect.top);
|
||||
|
||||
@ -338,4 +338,117 @@ void main() {
|
||||
expect(insideBottomRight, equals(outsideBottomRight));
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('FittedBox layers - contain', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const Center(
|
||||
child: const SizedBox(
|
||||
width: 100.0,
|
||||
height: 10.0,
|
||||
child: const FittedBox(
|
||||
fit: BoxFit.contain,
|
||||
child: const SizedBox(
|
||||
width: 50.0,
|
||||
height: 50.0,
|
||||
child: const RepaintBoundary(
|
||||
child: const Placeholder(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(getLayers(), <Type>[TransformLayer, TransformLayer, OffsetLayer]);
|
||||
});
|
||||
|
||||
testWidgets('FittedBox layers - cover - horizontal', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const Center(
|
||||
child: const SizedBox(
|
||||
width: 100.0,
|
||||
height: 10.0,
|
||||
child: const FittedBox(
|
||||
fit: BoxFit.cover,
|
||||
child: const SizedBox(
|
||||
width: 10.0,
|
||||
height: 50.0,
|
||||
child: const RepaintBoundary(
|
||||
child: const Placeholder(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(getLayers(), <Type>[TransformLayer, ClipRectLayer, TransformLayer, OffsetLayer]);
|
||||
});
|
||||
|
||||
testWidgets('FittedBox layers - cover - vertical', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const Center(
|
||||
child: const SizedBox(
|
||||
width: 10.0,
|
||||
height: 100.0,
|
||||
child: const FittedBox(
|
||||
fit: BoxFit.cover,
|
||||
child: const SizedBox(
|
||||
width: 50.0,
|
||||
height: 10.0,
|
||||
child: const RepaintBoundary(
|
||||
child: const Placeholder(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(getLayers(), <Type>[TransformLayer, ClipRectLayer, TransformLayer, OffsetLayer]);
|
||||
});
|
||||
|
||||
testWidgets('FittedBox layers - none - clip', (WidgetTester tester) async {
|
||||
final List<double> values = <double>[10.0, 50.0, 100.0];
|
||||
for (double a in values) {
|
||||
for (double b in values) {
|
||||
for (double c in values) {
|
||||
for (double d in values) {
|
||||
await tester.pumpWidget(
|
||||
new Center(
|
||||
child: new SizedBox(
|
||||
width: a,
|
||||
height: b,
|
||||
child: new FittedBox(
|
||||
fit: BoxFit.none,
|
||||
child: new SizedBox(
|
||||
width: c,
|
||||
height: d,
|
||||
child: const RepaintBoundary(
|
||||
child: const Placeholder(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
if (a < c || b < d) {
|
||||
expect(getLayers(), <Type>[TransformLayer, ClipRectLayer, OffsetLayer]);
|
||||
} else {
|
||||
expect(getLayers(), <Type>[TransformLayer, OffsetLayer]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
List<Type> getLayers() {
|
||||
final List<Type> layers = <Type>[];
|
||||
Layer layer = RendererBinding.instance.renderView.debugLayer;
|
||||
while (layer is ContainerLayer) {
|
||||
final ContainerLayer container = layer;
|
||||
layers.add(container.runtimeType);
|
||||
expect(container.firstChild, same(container.lastChild));
|
||||
layer = container.firstChild;
|
||||
}
|
||||
return layers;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user