Unverified Commit 9423a012 authored by chunhtai's avatar chunhtai Committed by GitHub

fix flutter error report correct local widget (#41224)

parent 532a8fed
<<skip until matching line>>
══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
The following assertion was thrown during layout:
A RenderFlex overflowed by 2844 pixels on the right\.
The relevant error-causing widget was:
Row
file:\/\/\/.+print_correct_local_widget_test\.dart:[0-9]+:[0-9]+
The overflowing RenderFlex has an orientation of Axis.horizontal\.
// Copyright 2019 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/widgets.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Rendering Error', (WidgetTester tester) async {
// This should fail with user created widget = Row.
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('RenderFlex OverFlow'),
),
body: Container(
width: 400.0,
child: Row(
children: <Widget>[
Icon(Icons.message),
Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: const <Widget>[
Text('Title'),
Text(
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed'
'do eiusmod tempor incididunt ut labore et dolore magna '
'aliqua. Ut enim ad minim veniam, quis nostrud '
'exercitation ullamco laboris nisi ut aliquip ex ea '
'commodo consequat.'
),
],
),
],
),
),
),
)
);
});
}
......@@ -9,7 +9,7 @@ more information in this error message to help you determine and fix the underly
In either case, please report this assertion by filing a bug on GitHub:
https:\/\/github\.com\/flutter\/flutter\/issues\/new\?template=BUG\.md
User-created ancestor of the error-causing widget was:
The relevant error-causing widget was:
CustomScrollView
file:\/\/\/.+print_user_created_ancestor_test\.dart:[0-9]+:7
......
......@@ -2806,15 +2806,15 @@ Iterable<DiagnosticsNode> _describeRelevantUserCode(Element element) {
];
}
final List<DiagnosticsNode> nodes = <DiagnosticsNode>[];
element.visitAncestorElements((Element ancestor) {
bool processElement(Element target) {
// TODO(chunhtai): should print out all the widgets that are about to cross
// package boundaries.
if (_isLocalCreationLocation(ancestor)) {
if (_isLocalCreationLocation(target)) {
nodes.add(
DiagnosticsBlock(
name: 'User-created ancestor of the error-causing widget was',
name: 'The relevant error-causing widget was',
children: <DiagnosticsNode>[
ErrorDescription('${ancestor.widget.toStringShort()} ${_describeCreationLocation(ancestor)}'),
ErrorDescription('${target.widget.toStringShort()} ${_describeCreationLocation(target)}'),
],
),
);
......@@ -2822,7 +2822,9 @@ Iterable<DiagnosticsNode> _describeRelevantUserCode(Element element) {
return false;
}
return true;
});
}
if (processElement(element))
element.visitAncestorElements(processElement);
return nodes;
}
......
......@@ -65,6 +65,12 @@ void main() {
return _testFile('print_user_created_ancestor_no_flag', automatedTestsDirectory, flutterTestDirectory);
}, skip: io.Platform.isWindows); // TODO(chunhtai): Dart on Windows has trouble with unicode characters in output (#35425).
testUsingContext('report correct created widget caused the error', () async {
Cache.flutterRoot = '../..';
return _testFile('print_correct_local_widget', automatedTestsDirectory, flutterTestDirectory,
extraArguments: const <String>['--track-widget-creation']);
}, skip: io.Platform.isWindows); // TODO(chunhtai): Dart on Windows has trouble with unicode characters in output (#35425).
testUsingContext('can load assets within its own package', () async {
Cache.flutterRoot = '../..';
return _testFile('package_assets', automatedTestsDirectory, flutterTestDirectory, exitCode: isZero);
......
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