Unverified Commit 1b2ee411 authored by Kenzie Davisson's avatar Kenzie Davisson Committed by GitHub

Sort diagnostics node dependencies so that order is stable (#105319)

* Sort diagnostics node dependencies so that order is stable

* use toDescription

* use toStringShort when possible

* sort InheritedElements
parent 95eb7a31
......@@ -4452,8 +4452,12 @@ abstract class Element extends DiagnosticableTree implements BuildContext {
properties.add(DiagnosticsProperty<Key>('key', _widget?.key, showName: false, defaultValue: null, level: DiagnosticLevel.hidden));
_widget?.debugFillProperties(properties);
properties.add(FlagProperty('dirty', value: dirty, ifTrue: 'dirty'));
if (_dependencies != null && _dependencies!.isNotEmpty) {
final List<DiagnosticsNode> diagnosticsDependencies = _dependencies!
final Set<InheritedElement>? deps = _dependencies;
if (deps != null && deps.isNotEmpty) {
final List<InheritedElement> sortedDependencies = deps.toList()
..sort((InheritedElement a, InheritedElement b) =>
a.toStringShort().compareTo(b.toStringShort()));
final List<DiagnosticsNode> diagnosticsDependencies = sortedDependencies
.map((InheritedElement element) => element.widget.toDiagnosticsNode(style: DiagnosticsTreeStyle.sparse))
.toList();
properties.add(DiagnosticsProperty<List<DiagnosticsNode>>('dependencies', diagnosticsDependencies));
......
......@@ -1558,6 +1558,50 @@ void main() {
expect(builder.properties.any((DiagnosticsNode property) => property.name == 'renderObject' && property.value == null), isTrue);
});
testWidgets('debugFillProperties sorts dependencies in alphabetical order', (WidgetTester tester) async {
final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
final TestRenderObjectElement element = TestRenderObjectElement();
final _TestInheritedElement focusTraversalOrder =
_TestInheritedElement(const FocusTraversalOrder(
order: LexicalFocusOrder(''),
child: Placeholder(),
));
final _TestInheritedElement directionality =
_TestInheritedElement(const Directionality(
textDirection: TextDirection.ltr,
child: Placeholder(),
));
final _TestInheritedElement buttonBarTheme =
_TestInheritedElement(const ButtonBarTheme(
data: ButtonBarThemeData(
alignment: MainAxisAlignment.center,
),
child: Placeholder(),
));
// Dependencies are added out of alphabetical order.
element
..dependOnInheritedElement(focusTraversalOrder)
..dependOnInheritedElement(directionality)
..dependOnInheritedElement(buttonBarTheme);
// Dependencies will be sorted by [debugFillProperties].
element.debugFillProperties(builder);
expect(
builder.properties.any((DiagnosticsNode property) => property.name == 'dependencies' && property.value != null),
isTrue,
);
final DiagnosticsProperty<List<DiagnosticsNode>> dependenciesProperty =
builder.properties.firstWhere((DiagnosticsNode property) => property.name == 'dependencies') as DiagnosticsProperty<List<DiagnosticsNode>>;
expect(dependenciesProperty, isNotNull);
final List<DiagnosticsNode> dependencies = dependenciesProperty.value!;
expect(dependencies.length, equals(3));
expect(dependencies.toString(), '[ButtonBarTheme, Directionality, FocusTraversalOrder]');
});
testWidgets('BuildOwner.globalKeyCount keeps track of in-use global keys', (WidgetTester tester) async {
final int initialCount = tester.binding.buildOwner!.globalKeyCount;
final GlobalKey key1 = GlobalKey();
......
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