fix flutter error report correct local widget (#41224)

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 0000000..33c3393
--- /dev/null
+++ b/dev/automated_tests/flutter_test/print_correct_local_widget_expectation.txt
@@ -0,0 +1,10 @@
+<<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\.
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 0000000..f123f24
--- /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: <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.'
+                    ),
+                  ],
+                ),
+              ],
+            ),
+          ),
+        ),
+      )
+    );
+  });
+}
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 997c784..0012864 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 @@
 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 14a5566..c3a6042 100644
--- a/packages/flutter/lib/src/widgets/widget_inspector.dart
+++ b/packages/flutter/lib/src/widgets/widget_inspector.dart
@@ -2806,15 +2806,15 @@
     ];
   }
   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 @@
       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 571629d..6b91db7 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 @@
       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);