diff --git a/dev/automated_tests/flutter_test/print_correct_local_widget_expectation.txt b/dev/automated_tests/flutter_test/print_correct_local_widget_expectation.txt new file mode 100644 index 0000000000..33c3393318 --- /dev/null +++ b/dev/automated_tests/flutter_test/print_correct_local_widget_expectation.txt @@ -0,0 +1,10 @@ +<> +══╡ 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\. diff --git a/dev/automated_tests/flutter_test/print_correct_local_widget_test.dart b/dev/automated_tests/flutter_test/print_correct_local_widget_test.dart new file mode 100644 index 0000000000..f123f24c26 --- /dev/null +++ b/dev/automated_tests/flutter_test/print_correct_local_widget_test.dart @@ -0,0 +1,44 @@ +// 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: [ + Icon(Icons.message), + Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: const [ + 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.' + ), + ], + ), + ], + ), + ), + ), + ) + ); + }); +} diff --git a/dev/automated_tests/flutter_test/print_user_created_ancestor_expectation.txt b/dev/automated_tests/flutter_test/print_user_created_ancestor_expectation.txt index 997c784368..0012864977 100644 --- a/dev/automated_tests/flutter_test/print_user_created_ancestor_expectation.txt +++ b/dev/automated_tests/flutter_test/print_user_created_ancestor_expectation.txt @@ -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 diff --git a/packages/flutter/lib/src/widgets/widget_inspector.dart b/packages/flutter/lib/src/widgets/widget_inspector.dart index 14a5566aa2..c3a60421d8 100644 --- a/packages/flutter/lib/src/widgets/widget_inspector.dart +++ b/packages/flutter/lib/src/widgets/widget_inspector.dart @@ -2806,15 +2806,15 @@ Iterable _describeRelevantUserCode(Element element) { ]; } final List nodes = []; - 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: [ - ErrorDescription('${ancestor.widget.toStringShort()} ${_describeCreationLocation(ancestor)}'), + ErrorDescription('${target.widget.toStringShort()} ${_describeCreationLocation(target)}'), ], ), ); @@ -2822,7 +2822,9 @@ Iterable _describeRelevantUserCode(Element element) { return false; } return true; - }); + } + if (processElement(element)) + element.visitAncestorElements(processElement); return nodes; } diff --git a/packages/flutter_tools/test/commands.shard/permeable/test_test.dart b/packages/flutter_tools/test/commands.shard/permeable/test_test.dart index 571629d383..6b91db727b 100644 --- a/packages/flutter_tools/test/commands.shard/permeable/test_test.dart +++ b/packages/flutter_tools/test/commands.shard/permeable/test_test.dart @@ -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 ['--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);