You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add support for setting the heading level for web semantics (#97894) (#125771)
This change adds a new property in Semantics widget that would take an integer corresponding to the heading levels defined by the ARIA heading role. This is necessary in order to get proper accessibility and usability in a website for users who rely on screen readers and other assistive technologies.
Issue fixed by this PR:
fixesflutter/flutter#97894
Engine part:
flutter/engine#41435
Copy file name to clipboardExpand all lines: packages/flutter/lib/src/semantics/semantics.dart
+59-5
Original file line number
Diff line number
Diff line change
@@ -446,6 +446,7 @@ class SemanticsData with Diagnosticable {
446
446
requiredthis.platformViewId,
447
447
requiredthis.maxValueLength,
448
448
requiredthis.currentValueLength,
449
+
requiredthis.headingLevel,
449
450
this.tags,
450
451
this.transform,
451
452
this.customSemanticsActionIds,
@@ -454,7 +455,8 @@ class SemanticsData with Diagnosticable {
454
455
assert(attributedValue.string ==''|| textDirection !=null, 'A SemanticsData object with value "${attributedValue.string}" had a null textDirection.'),
455
456
assert(attributedDecreasedValue.string ==''|| textDirection !=null, 'A SemanticsData object with decreasedValue "${attributedDecreasedValue.string}" had a null textDirection.'),
456
457
assert(attributedIncreasedValue.string ==''|| textDirection !=null, 'A SemanticsData object with increasedValue "${attributedIncreasedValue.string}" had a null textDirection.'),
457
-
assert(attributedHint.string ==''|| textDirection !=null, 'A SemanticsData object with hint "${attributedHint.string}" had a null textDirection.');
458
+
assert(attributedHint.string ==''|| textDirection !=null, 'A SemanticsData object with hint "${attributedHint.string}" had a null textDirection.'),
459
+
assert(headingLevel >=0&& headingLevel <=6, 'Heading level must be between 0 and 6');
458
460
459
461
/// A bit field of [SemanticsFlag]s that apply to this node.
460
462
finalint flags;
@@ -547,6 +549,12 @@ class SemanticsData with Diagnosticable {
547
549
/// The reading direction is given by [textDirection].
548
550
finalString tooltip;
549
551
552
+
/// Indicates that this subtree represents a heading.
553
+
///
554
+
/// A value of 0 indicates that it is not a heading. The value should be a
555
+
/// number between 1 and 6, indicating the hierarchical level as a heading.
556
+
finalint headingLevel;
557
+
550
558
/// The reading direction for the text in [label], [value],
551
559
/// [increasedValue], [decreasedValue], and [hint].
552
560
finalTextDirection? textDirection;
@@ -719,6 +727,7 @@ class SemanticsData with Diagnosticable {
0 commit comments