Do not paint a RenderFittedBox with an empty size (#7489)

If the size is empty, then _updatePaintData will produce an invalid transform
that yields a NaN canvas bounds rectangle

Fixes https://github.com/flutter/flutter/issues/7431
This commit is contained in:
Jason Simmons 2017-01-13 15:12:30 -08:00 committed by GitHub
parent 113fd6cb52
commit 3b702448fd
2 changed files with 34 additions and 0 deletions

View File

@ -1573,6 +1573,8 @@ class RenderFittedBox extends RenderProxyBox {
@override
void paint(PaintingContext context, Offset offset) {
if (size.isEmpty)
return;
_updatePaintData();
if (child != null) {
if (_hasVisualOverflow)

View File

@ -0,0 +1,32 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/rendering.dart';
import 'package:test/test.dart';
import 'rendering_tester.dart';
void main() {
test('RenderFittedBox paint', () {
bool painted;
RenderFittedBox makeFittedBox() {
return new RenderFittedBox(
child: new RenderCustomPaint(
painter: new TestCallbackPainter(
onPaint: () { painted = true; }
),
),
);
}
painted = false;
layout(makeFittedBox(), phase: EnginePhase.paint);
expect(painted, equals(true));
// The RenderFittedBox should not paint if it is empty.
painted = false;
layout(makeFittedBox(), constraints: new BoxConstraints.tight(Size.zero), phase: EnginePhase.paint);
expect(painted, equals(false));
});
}