Unverified Commit 06f86c8b authored by liyuqian's avatar liyuqian Committed by GitHub

Reland matrix check (#32521)

This relands flutter/flutter#31701 with missing const added

This reverts commit 549b4126.
parent 1cd88c35
......@@ -1228,7 +1228,8 @@ class TransformLayer extends OffsetLayer {
/// The [transform] and [offset] properties must be non-null before the
/// compositing phase of the pipeline.
TransformLayer({ Matrix4 transform, Offset offset = Offset.zero })
: _transform = transform,
: assert(transform.storage.every((double value) => value.isFinite)),
_transform = transform,
super(offset: offset);
/// The matrix to apply.
......
......@@ -2280,9 +2280,11 @@ class RenderFittedBox extends RenderProxyBox {
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.height;
assert(scaleX.isFinite && scaleY.isFinite);
_transform = Matrix4.translationValues(destinationRect.left, destinationRect.top, 0.0)
..scale(scaleX, scaleY, 1.0)
..translate(-sourceRect.left, -sourceRect.top);
assert(_transform.storage.every((double value) => value.isFinite));
}
}
......@@ -2296,7 +2298,7 @@ class RenderFittedBox extends RenderProxyBox {
@override
void paint(PaintingContext context, Offset offset) {
if (size.isEmpty)
if (size.isEmpty || child.size.isEmpty)
return;
_updatePaintData();
if (child != null) {
......
......@@ -15,11 +15,12 @@ import '../flutter_test_alternative.dart';
import 'rendering_tester.dart';
void main() {
test('RenderFittedBox paint', () {
test('RenderFittedBox does not paint with empty sizes', () {
bool painted;
RenderFittedBox makeFittedBox() {
RenderFittedBox makeFittedBox(Size size) {
return RenderFittedBox(
child: RenderCustomPaint(
preferredSize: size,
painter: TestCallbackPainter(onPaint: () {
painted = true;
}),
......@@ -27,13 +28,19 @@ void main() {
);
}
// The RenderFittedBox paints if both its size and its child's size are nonempty.
painted = false;
layout(makeFittedBox(), phase: EnginePhase.paint);
layout(makeFittedBox(const Size(1, 1)), phase: EnginePhase.paint);
expect(painted, equals(true));
// The RenderFittedBox should not paint if its child is empty-sized.
painted = false;
layout(makeFittedBox(Size.zero), phase: EnginePhase.paint);
expect(painted, equals(false));
// The RenderFittedBox should not paint if it is empty.
painted = false;
layout(makeFittedBox(), constraints: BoxConstraints.tight(Size.zero), phase: EnginePhase.paint);
layout(makeFittedBox(const Size(1, 1)), constraints: BoxConstraints.tight(Size.zero), phase: EnginePhase.paint);
expect(painted, equals(false));
});
......
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