Unverified Commit 848cb83b authored by Norbert Kozsir's avatar Norbert Kozsir Committed by GitHub

Make _isLocalCreationLocation public (#62891)

parent c54b15b6
...@@ -2860,7 +2860,7 @@ Iterable<DiagnosticsNode> _describeRelevantUserCode(Element element) { ...@@ -2860,7 +2860,7 @@ Iterable<DiagnosticsNode> _describeRelevantUserCode(Element element) {
bool processElement(Element target) { bool processElement(Element target) {
// TODO(chunhtai): should print out all the widgets that are about to cross // TODO(chunhtai): should print out all the widgets that are about to cross
// package boundaries. // package boundaries.
if (_isLocalCreationLocation(target)) { if (debugIsLocalCreationLocation(target)) {
nodes.add( nodes.add(
DiagnosticsBlock( DiagnosticsBlock(
name: 'The relevant error-causing widget was', name: 'The relevant error-causing widget was',
...@@ -2881,15 +2881,22 @@ Iterable<DiagnosticsNode> _describeRelevantUserCode(Element element) { ...@@ -2881,15 +2881,22 @@ Iterable<DiagnosticsNode> _describeRelevantUserCode(Element element) {
/// Returns if an object is user created. /// Returns if an object is user created.
/// ///
/// This always returns false if it is not called in debug mode.
///
/// {@macro widgets.inspector.trackCreation} /// {@macro widgets.inspector.trackCreation}
/// ///
/// Currently is local creation locations are only available for /// Currently is local creation locations are only available for
/// [Widget] and [Element]. /// [Widget] and [Element].
bool _isLocalCreationLocation(Object object) { bool debugIsLocalCreationLocation(Object object) {
final _Location location = _getCreationLocation(object); bool isLocal = false;
if (location == null) assert(() {
return false; final _Location location = _getCreationLocation(object);
return WidgetInspectorService.instance._isLocalCreationLocation(location); if (location == null)
isLocal = false;
isLocal = WidgetInspectorService.instance._isLocalCreationLocation(location);
return true;
}());
return isLocal;
} }
/// Returns the creation location of an object in String format if one is available. /// Returns the creation location of an object in String format if one is available.
......
...@@ -2748,6 +2748,35 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -2748,6 +2748,35 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
); );
expect(node.toJsonMap(emptyDelegate), node.toJsonMap(defaultDelegate)); expect(node.toJsonMap(emptyDelegate), node.toJsonMap(defaultDelegate));
}); });
testWidgets('debugIsLocalCreationLocation test', (WidgetTester tester) async {
final GlobalKey key = GlobalKey();
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: Container(
padding: const EdgeInsets.all(8),
child: Text('target', key: key, textDirection: TextDirection.ltr),
),
),
);
final Element element = key.currentContext as Element;
expect(debugIsLocalCreationLocation(element), isTrue);
expect(debugIsLocalCreationLocation(element.widget), isTrue);
// Padding is inside container
final Finder paddingFinder = find.byType(Padding);
final Element paddingElement = paddingFinder.evaluate().first;
expect(debugIsLocalCreationLocation(paddingElement), isFalse);
expect(debugIsLocalCreationLocation(paddingElement.widget), isFalse);
}, skip: !WidgetInspectorService.instance.isWidgetCreationTracked()); // Test requires --track-widget-creation flag.
} }
} }
......
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