Unverified Commit 23f7985e authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

Improve how AttributedStrings are presented in the widget inspector (#92450)

parent bd935e5d
......@@ -2839,14 +2839,23 @@ class DiagnosticsProperty<T> extends DiagnosticsNode {
}
}
/// If the [value] of the property equals [defaultValue] the priority [level]
/// of the property is downgraded to [DiagnosticLevel.fine] as the property
/// value is uninteresting.
/// The default value of this property, when it has not been set to a specific
/// value.
///
/// For most [DiagnosticsProperty] classes, if the [value] of the property
/// equals [defaultValue], then the priority [level] of the property is
/// downgraded to [DiagnosticLevel.fine] on the basis that the property value
/// is uninteresting. This is implemented by [isInteresting].
///
/// The [defaultValue] is [kNoDefaultValue] by default. Otherwise it must be of
/// type `T?`.
final Object? defaultValue;
/// Whether to consider the property's value interesting. When a property is
/// uninteresting, its [level] is downgraded to [DiagnosticLevel.fine]
/// regardless of the value provided as the constructor's `level` argument.
bool get isInteresting => defaultValue == kNoDefaultValue || value != defaultValue;
final DiagnosticLevel _defaultLevel;
/// Priority level of the diagnostic used to control which diagnostics should
......@@ -2870,8 +2879,7 @@ class DiagnosticsProperty<T> extends DiagnosticsNode {
if (value == null && missingIfNull)
return DiagnosticLevel.warning;
// Use a low level when the value matches the default value.
if (defaultValue != kNoDefaultValue && value == defaultValue)
if (!isInteresting)
return DiagnosticLevel.fine;
return _defaultLevel;
......@@ -3549,7 +3557,9 @@ class DiagnosticsBlock extends DiagnosticsNode {
@override
final DiagnosticLevel level;
final String? _description;
@override
final Object? value;
......
......@@ -69,6 +69,10 @@ void main() {
expect(config.label, 'label1');
expect(config.attributedLabel.string, 'label1');
expect(config.attributedLabel.attributes.isEmpty, isTrue);
expect(
(SemanticsNode()..updateWith(config: config)).toString(),
'SemanticsNode#1(STALE, owner: null, Rect.fromLTRB(0.0, 0.0, 0.0, 0.0), invisible, label: "label1")',
);
config.attributedLabel = AttributedString(
'label2',
......@@ -81,16 +85,28 @@ void main() {
expect(config.attributedLabel.attributes.length, 1);
expect(config.attributedLabel.attributes[0] is SpellOutStringAttribute, isTrue);
expect(config.attributedLabel.attributes[0].range, const TextRange(start: 0, end: 1));
expect(
(SemanticsNode()..updateWith(config: config)).toString(),
'SemanticsNode#2(STALE, owner: null, Rect.fromLTRB(0.0, 0.0, 0.0, 0.0), invisible, label: "label2" [SpellOutStringAttribute(TextRange(start: 0, end: 1))])',
);
config.label = 'label3';
expect(config.label, 'label3');
expect(config.attributedLabel.string, 'label3');
expect(config.attributedLabel.attributes.isEmpty, isTrue);
expect(
(SemanticsNode()..updateWith(config: config)).toString(),
'SemanticsNode#3(STALE, owner: null, Rect.fromLTRB(0.0, 0.0, 0.0, 0.0), invisible, label: "label3")',
);
config.value = 'value1';
expect(config.value, 'value1');
expect(config.attributedValue.string, 'value1');
expect(config.attributedValue.attributes.isEmpty, isTrue);
expect(
(SemanticsNode()..updateWith(config: config)).toString(),
'SemanticsNode#4(STALE, owner: null, Rect.fromLTRB(0.0, 0.0, 0.0, 0.0), invisible, label: "label3", value: "value1")',
);
config.attributedValue = AttributedString(
'value2',
......@@ -103,16 +119,28 @@ void main() {
expect(config.attributedValue.attributes.length, 1);
expect(config.attributedValue.attributes[0] is SpellOutStringAttribute, isTrue);
expect(config.attributedValue.attributes[0].range, const TextRange(start: 0, end: 1));
expect(
(SemanticsNode()..updateWith(config: config)).toString(),
'SemanticsNode#5(STALE, owner: null, Rect.fromLTRB(0.0, 0.0, 0.0, 0.0), invisible, label: "label3", value: "value2" [SpellOutStringAttribute(TextRange(start: 0, end: 1))])',
);
config.value = 'value3';
expect(config.value, 'value3');
expect(config.attributedValue.string, 'value3');
expect(config.attributedValue.attributes.isEmpty, isTrue);
expect(
(SemanticsNode()..updateWith(config: config)).toString(),
'SemanticsNode#6(STALE, owner: null, Rect.fromLTRB(0.0, 0.0, 0.0, 0.0), invisible, label: "label3", value: "value3")',
);
config.hint = 'hint1';
expect(config.hint, 'hint1');
expect(config.attributedHint.string, 'hint1');
expect(config.attributedHint.attributes.isEmpty, isTrue);
expect(
(SemanticsNode()..updateWith(config: config)).toString(),
'SemanticsNode#7(STALE, owner: null, Rect.fromLTRB(0.0, 0.0, 0.0, 0.0), invisible, label: "label3", value: "value3", hint: "hint1")',
);
config.attributedHint = AttributedString(
'hint2',
......@@ -125,11 +153,19 @@ void main() {
expect(config.attributedHint.attributes.length, 1);
expect(config.attributedHint.attributes[0] is SpellOutStringAttribute, isTrue);
expect(config.attributedHint.attributes[0].range, const TextRange(start: 0, end: 1));
expect(
(SemanticsNode()..updateWith(config: config)).toString(),
'SemanticsNode#8(STALE, owner: null, Rect.fromLTRB(0.0, 0.0, 0.0, 0.0), invisible, label: "label3", value: "value3", hint: "hint2" [SpellOutStringAttribute(TextRange(start: 0, end: 1))])',
);
config.hint = 'hint3';
expect(config.hint, 'hint3');
expect(config.attributedHint.string, 'hint3');
expect(config.attributedHint.attributes.isEmpty, isTrue);
expect(
(SemanticsNode()..updateWith(config: config)).toString(),
'SemanticsNode#9(STALE, owner: null, Rect.fromLTRB(0.0, 0.0, 0.0, 0.0), invisible, label: "label3", value: "value3", hint: "hint3")',
);
});
test('mutate existing semantic node list errors', () {
......@@ -654,6 +690,7 @@ void main() {
expect(result.attributes.length, 2);
expect(result.attributes[0].range, const TextRange(start:0, end:4));
expect(result.attributes[0] is SpellOutStringAttribute, isTrue);
expect(result.toString(), "AttributedString('string1string2', attributes: [SpellOutStringAttribute(TextRange(start: 0, end: 4)), LocaleStringAttribute(TextRange(start: 7, end: 11), es-MX)])");
});
test('Semantics id does not repeat', () {
......
......@@ -151,6 +151,17 @@ void main() {
expect(SemanticsUpdateBuilderSpy.observations[1]!.hintAttributes![0] is SpellOutStringAttribute, isTrue);
expect(SemanticsUpdateBuilderSpy.observations[1]!.hintAttributes![0].range, const TextRange(start: 1, end: 2));
expect(
tester.widget(find.byType(Semantics)).toString(),
'Semantics('
'container: false, '
'properties: SemanticsProperties, '
'attributedLabel: "label" [SpellOutStringAttribute(TextRange(start: 0, end: 5))], '
'attributedValue: "value" [LocaleStringAttribute(TextRange(start: 0, end: 5), en-MX)], '
'attributedHint: "hint" [SpellOutStringAttribute(TextRange(start: 1, end: 2))]' // ignore: missing_whitespace_between_adjacent_strings
')',
);
SemanticsUpdateBuilderSpy.observations.clear();
handle.dispose();
});
......
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