Unverified Commit 7cc694e5 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

Track InheritedElement dependencies in diagnostic properties (#27387)

parent aa8f8613
......@@ -3431,6 +3431,12 @@ abstract class Element extends DiagnosticableTree implements BuildContext {
widget.debugFillProperties(properties);
}
properties.add(FlagProperty('dirty', value: dirty, ifTrue: 'dirty'));
if (_dependencies != null && _dependencies.isNotEmpty) {
final List<DiagnosticsNode> diagnosticsDependencies = _dependencies
.map((InheritedElement element) => element.widget.toDiagnosticsNode(style: DiagnosticsTreeStyle.sparse))
.toList();
properties.add(DiagnosticsProperty<List<DiagnosticsNode>>('dependencies', diagnosticsDependencies));
}
}
@override
......
// 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/src/widgets/basic.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('InheritedWidget dependencies show up in diagnostic properties', (WidgetTester tester) async {
final GlobalKey key = GlobalKey();
await tester.pumpWidget(Directionality(
key: key,
textDirection: TextDirection.ltr,
child: Builder(builder: (BuildContext context) {
Directionality.of(context);
return const SizedBox();
}),
));
final InheritedElement element = key.currentContext;
expect(
element.toStringDeep(minLevel: DiagnosticLevel.info),
equalsIgnoringHashCodes(
'Directionality-[GlobalKey#00000](textDirection: ltr)\n'
'└Builder(dependencies: [Directionality-[GlobalKey#00000]])\n'
' └SizedBox(renderObject: RenderConstrainedBox#00000)\n'
''
),
);
await tester.pumpWidget(Directionality(
key: key,
textDirection: TextDirection.rtl,
child: Builder(builder: (BuildContext context) {
Directionality.of(context);
return const SizedBox();
}),
));
expect(
element.toStringDeep(minLevel: DiagnosticLevel.info),
equalsIgnoringHashCodes(
'Directionality-[GlobalKey#00000](textDirection: rtl)\n'
'└Builder(dependencies: [Directionality-[GlobalKey#00000]])\n'
' └SizedBox(renderObject: RenderConstrainedBox#00000)\n'
''
),
);
});
}
......@@ -796,25 +796,25 @@ void main() {
expect(
element.toStringDeep(minLevel: DiagnosticLevel.info),
equalsIgnoringHashCodes(
'Table-[GlobalKey#00000](renderObject: RenderTable#00000)\n'
'Table-[GlobalKey#00000](dependencies: [Directionality], renderObject: RenderTable#00000)\n'
'├Text("A")\n'
'│└RichText(softWrap: wrapping at box width, maxLines: unlimited, text: "A", renderObject: RenderParagraph#00000 relayoutBoundary=up1)\n'
'│└RichText(softWrap: wrapping at box width, maxLines: unlimited, text: "A", dependencies: [Directionality], renderObject: RenderParagraph#00000 relayoutBoundary=up1)\n'
'├Text("B")\n'
'│└RichText(softWrap: wrapping at box width, maxLines: unlimited, text: "B", renderObject: RenderParagraph#00000 relayoutBoundary=up1)\n'
'│└RichText(softWrap: wrapping at box width, maxLines: unlimited, text: "B", dependencies: [Directionality], renderObject: RenderParagraph#00000 relayoutBoundary=up1)\n'
'├Text("C")\n'
'│└RichText(softWrap: wrapping at box width, maxLines: unlimited, text: "C", renderObject: RenderParagraph#00000 relayoutBoundary=up1)\n'
'│└RichText(softWrap: wrapping at box width, maxLines: unlimited, text: "C", dependencies: [Directionality], renderObject: RenderParagraph#00000 relayoutBoundary=up1)\n'
'├Text("D")\n'
'│└RichText(softWrap: wrapping at box width, maxLines: unlimited, text: "D", renderObject: RenderParagraph#00000 relayoutBoundary=up1)\n'
'│└RichText(softWrap: wrapping at box width, maxLines: unlimited, text: "D", dependencies: [Directionality], renderObject: RenderParagraph#00000 relayoutBoundary=up1)\n'
'├Text("EEE")\n'
'│└RichText(softWrap: wrapping at box width, maxLines: unlimited, text: "EEE", renderObject: RenderParagraph#00000 relayoutBoundary=up1)\n'
'│└RichText(softWrap: wrapping at box width, maxLines: unlimited, text: "EEE", dependencies: [Directionality], renderObject: RenderParagraph#00000 relayoutBoundary=up1)\n'
'├Text("F")\n'
'│└RichText(softWrap: wrapping at box width, maxLines: unlimited, text: "F", renderObject: RenderParagraph#00000 relayoutBoundary=up1)\n'
'│└RichText(softWrap: wrapping at box width, maxLines: unlimited, text: "F", dependencies: [Directionality], renderObject: RenderParagraph#00000 relayoutBoundary=up1)\n'
'├Text("G")\n'
'│└RichText(softWrap: wrapping at box width, maxLines: unlimited, text: "G", renderObject: RenderParagraph#00000 relayoutBoundary=up1)\n'
'│└RichText(softWrap: wrapping at box width, maxLines: unlimited, text: "G", dependencies: [Directionality], renderObject: RenderParagraph#00000 relayoutBoundary=up1)\n'
'├Text("H")\n'
'│└RichText(softWrap: wrapping at box width, maxLines: unlimited, text: "H", renderObject: RenderParagraph#00000 relayoutBoundary=up1)\n'
'│└RichText(softWrap: wrapping at box width, maxLines: unlimited, text: "H", dependencies: [Directionality], renderObject: RenderParagraph#00000 relayoutBoundary=up1)\n'
'└Text("III")\n'
' └RichText(softWrap: wrapping at box width, maxLines: unlimited, text: "III", renderObject: RenderParagraph#00000 relayoutBoundary=up1)\n'
' └RichText(softWrap: wrapping at box width, maxLines: unlimited, text: "III", dependencies: [Directionality], renderObject: RenderParagraph#00000 relayoutBoundary=up1)\n'
),
);
});
......
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