mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
RenderBlock wasn't constraining the results. RenderPadding wasn't constraining the results (which matters especially when the constraints can't fit the padding in the first place). RenderViewport wasn't constraining the results. Add a test for the block case. To catch this kind of thing in the future, add some asserts to debugDoesMeetConstraints() that all four intrinsic functions return values that are within the constraints. RenderBlockViewport doesn't support returning intrinsics, so turn off the "no intrinsic support" asserts (and return zero) when we're doing this new assert. This new assert screwed up the custom layout classes' tests, so adjust those tests to ignore the callbacks invoked from these asserts. Add to the _debugReportException() method a short summary of the descendants of this node. It's important to have this information when debugging errors like these intrinsic constraints contract violations because often nodes just pass the values through to their child so you have to go several steps down to find the actual problem. Fixes https://github.com/flutter/flutter/issues/1210
89 lines
3.5 KiB
Dart
89 lines
3.5 KiB
Dart
// Copyright 2015 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/material.dart';
|
|
import 'package:flutter/rendering.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
import 'rendering_tester.dart';
|
|
|
|
class TestBlockPainter extends Painter {
|
|
void paint(PaintingContext context, Offset offset) { }
|
|
}
|
|
|
|
void main() {
|
|
test('block intrinsics', () {
|
|
RenderParagraph paragraph = new RenderParagraph(
|
|
new StyledTextSpan(
|
|
new TextStyle(
|
|
height: 1.0
|
|
),
|
|
<TextSpan>[new PlainTextSpan('Hello World')]
|
|
)
|
|
);
|
|
const BoxConstraints unconstrained = const BoxConstraints();
|
|
double textWidth = paragraph.getMaxIntrinsicWidth(unconstrained);
|
|
double oneLineTextHeight = paragraph.getMinIntrinsicHeight(unconstrained);
|
|
final BoxConstraints constrained = new BoxConstraints(maxWidth: textWidth * 0.9);
|
|
double wrappedTextWidth = paragraph.getMinIntrinsicWidth(unconstrained);
|
|
double twoLinesTextHeight = paragraph.getMinIntrinsicHeight(constrained);
|
|
|
|
// controls
|
|
expect(wrappedTextWidth, lessThan(textWidth));
|
|
expect(paragraph.getMinIntrinsicWidth(unconstrained), equals(wrappedTextWidth));
|
|
expect(paragraph.getMaxIntrinsicWidth(constrained), equals(constrained.maxWidth));
|
|
|
|
expect(oneLineTextHeight, lessThan(twoLinesTextHeight));
|
|
expect(twoLinesTextHeight, lessThan(oneLineTextHeight * 3.0));
|
|
expect(paragraph.getMaxIntrinsicHeight(unconstrained), equals(oneLineTextHeight));
|
|
expect(paragraph.getMaxIntrinsicHeight(constrained), equals(twoLinesTextHeight));
|
|
|
|
RenderBox testBlock = new RenderBlock(
|
|
children: <RenderBox>[
|
|
paragraph,
|
|
]
|
|
);
|
|
expect(testBlock.getMinIntrinsicWidth(unconstrained), equals(wrappedTextWidth));
|
|
expect(testBlock.getMinIntrinsicWidth(constrained), equals(wrappedTextWidth));
|
|
expect(testBlock.getMaxIntrinsicWidth(unconstrained), equals(textWidth));
|
|
expect(testBlock.getMaxIntrinsicWidth(constrained), equals(constrained.maxWidth));
|
|
expect(testBlock.getMinIntrinsicHeight(unconstrained), equals(oneLineTextHeight));
|
|
expect(testBlock.getMinIntrinsicHeight(constrained), equals(twoLinesTextHeight));
|
|
expect(testBlock.getMaxIntrinsicHeight(unconstrained), equals(oneLineTextHeight));
|
|
expect(testBlock.getMaxIntrinsicHeight(constrained), equals(twoLinesTextHeight));
|
|
|
|
final BoxConstraints empty = new BoxConstraints.tight(Size.zero);
|
|
expect(testBlock.getMinIntrinsicWidth(empty), equals(0.0));
|
|
expect(testBlock.getMaxIntrinsicWidth(empty), equals(0.0));
|
|
expect(testBlock.getMinIntrinsicHeight(empty), equals(0.0));
|
|
expect(testBlock.getMaxIntrinsicHeight(empty), equals(0.0));
|
|
});
|
|
|
|
|
|
test('overlay painters can attach and detach', () {
|
|
TestBlockPainter first = new TestBlockPainter();
|
|
TestBlockPainter second = new TestBlockPainter();
|
|
RenderBlockViewport block = new RenderBlockViewport(overlayPainter: first);
|
|
|
|
// The first painter isn't attached because we haven't attached block.
|
|
expect(first.renderObject, isNull);
|
|
expect(second.renderObject, isNull);
|
|
|
|
block.overlayPainter = second;
|
|
|
|
expect(first.renderObject, isNull);
|
|
expect(second.renderObject, isNull);
|
|
|
|
layout(block);
|
|
|
|
expect(first.renderObject, isNull);
|
|
expect(second.renderObject, equals(block));
|
|
|
|
block.overlayPainter = first;
|
|
|
|
expect(first.renderObject, equals(block));
|
|
expect(second.renderObject, isNull);
|
|
});
|
|
}
|