Error message when size has not been set in RenderBox's performLayout should be well versed (#58151)

This commit is contained in:
Hansol Lee
2020-05-29 07:03:01 +09:00
committed by GitHub
parent 525c5ccde8
commit e853155c7e
2 changed files with 34 additions and 1 deletions

View File

@@ -1927,7 +1927,6 @@ abstract class RenderBox extends RenderObject {
assert(constraints != null);
assert(() {
if (!hasSize) {
assert(!debugNeedsLayout); // this is called in the size= setter during layout, but in that case we have a size
DiagnosticsNode contract;
if (sizedByParent)
contract = ErrorDescription('Because this RenderBox has sizedByParent set to true, it must set its size in performResize().');

View File

@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
@@ -30,6 +31,11 @@ class FakeMissingSizeRenderBox extends RenderBox {
bool fakeMissingSize = false;
}
class MissingSetSizeRenderBox extends RenderBox {
@override
void performLayout() { }
}
void main() {
test('should size to render view', () {
final RenderBox root = RenderDecoratedBox(
@@ -1014,6 +1020,34 @@ void main() {
expect(() => BoxConstraints(minHeight: null), throwsAssertionError);
expect(() => BoxConstraints(maxHeight: null), throwsAssertionError);
});
test('Error message when size has not been set in RenderBox performLayout should be well versed', () {
FlutterErrorDetails errorDetails;
final FlutterExceptionHandler oldHandler = FlutterError.onError;
FlutterError.onError = (FlutterErrorDetails details) {
errorDetails = details;
};
try {
MissingSetSizeRenderBox().layout(const BoxConstraints());
} finally {
FlutterError.onError = oldHandler;
}
expect(errorDetails, isNotNull);
// Check the ErrorDetails without the stack trace.
final List<String> lines = errorDetails.toString().split('\n');
expect(
lines.take(5).join('\n'),
equalsIgnoringHashCodes(
'══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞══════════════════════\n'
'The following assertion was thrown during performLayout():\n'
'RenderBox did not set its size during layout.\n'
'Because this RenderBox has sizedByParent set to false, it must\n'
'set its size in performLayout().'
),
);
});
}
class _DummyHitTestTarget implements HitTestTarget {