Unverified Commit e853155c authored by Hansol Lee's avatar Hansol Lee Committed by GitHub

Error message when size has not been set in RenderBox's performLayout should...

Error message when size has not been set in RenderBox's performLayout should be well versed (#58151)
parent 525c5ccd
......@@ -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().');
......
......@@ -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 {
......
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