Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit cc08940

Browse files
authored
null-annotate SemanticsUpdateBuilder.updateNode (#18552)
The underlying _updateNode call requires that all parameters be set non-null. There's a single call site in the framework in lib/src/semantics/semantics.dart in SemanticsNode.updateWith(). At that call site, all parameters are either asserted non-null in the constructor of SemanticsData or defaulted to null, with the sole exception of textDirection. The ergonomics of this method are currently pretty ugly and we should consider migrating most of the defaulting and assertions that we apply at the call site up to the definition in dart:ui. That work is filed as flutter/flutter#57720.
1 parent 859d892 commit cc08940

File tree

2 files changed

+143
-95
lines changed

2 files changed

+143
-95
lines changed

lib/ui/semantics.dart

Lines changed: 91 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -647,19 +647,21 @@ class SemanticsUpdateBuilder extends NativeFieldWrapperClass2 {
647647
/// reading direction of all these strings is given by `textDirection`.
648648
///
649649
/// The fields `textSelectionBase` and `textSelectionExtent` describe the
650-
/// currently selected text within `value`.
650+
/// currently selected text within `value`. A value of -1 indicates no
651+
/// current text selection base or extent.
651652
///
652-
/// The field `maxValueLength` is used to indicate that an editable text field
653-
/// has a limit on the number of characters entered. If it is -1 there is
654-
/// no limit on the number of characters entered. The field
653+
/// The field `maxValueLength` is used to indicate that an editable text
654+
/// field has a limit on the number of characters entered. If it is -1 there
655+
/// is no limit on the number of characters entered. The field
655656
/// `currentValueLength` indicates how much of that limit has already been
656-
/// used up. When `maxValueLength` is set, `currentValueLength` must also be
657-
/// set.
657+
/// used up. When `maxValueLength` is >= 0, `currentValueLength` must also be
658+
/// >= 0, otherwise it should be specified to be -1.
658659
///
659660
/// The field `platformViewId` references the platform view, whose semantics
660661
/// nodes will be added as children to this node. If a platform view is
661-
/// specified, `childrenInHitTestOrder` and `childrenInTraversalOrder` must be
662-
/// empty.
662+
/// specified, `childrenInHitTestOrder` and `childrenInTraversalOrder` must
663+
/// be empty. A value of -1 indicates that this node is not associated with a
664+
/// platform view.
663665
///
664666
/// For scrollable nodes `scrollPosition` describes the current scroll
665667
/// position in logical pixel. `scrollExtentMax` and `scrollExtentMin`
@@ -683,39 +685,61 @@ class SemanticsUpdateBuilder extends NativeFieldWrapperClass2 {
683685
/// z-direction starting at `elevation`. Basically, in the z-direction the
684686
/// node starts at `elevation` above the parent and ends at `elevation` +
685687
/// `thickness` above the parent.
688+
// TODO(cbracken): https://github.com/flutter/flutter/issues/57720
686689
void updateNode({
687-
int id,
688-
int flags,
689-
int actions,
690-
int maxValueLength,
691-
int currentValueLength,
692-
int textSelectionBase,
693-
int textSelectionExtent,
694-
int platformViewId,
695-
int scrollChildren,
696-
int scrollIndex,
697-
double scrollPosition,
698-
double scrollExtentMax,
699-
double scrollExtentMin,
700-
double elevation,
701-
double thickness,
702-
Rect rect,
703-
String label,
704-
String hint,
705-
String value,
706-
String increasedValue,
707-
String decreasedValue,
708-
TextDirection textDirection,
709-
Float64List transform,
710-
Int32List childrenInTraversalOrder,
711-
Int32List childrenInHitTestOrder,
712-
Int32List additionalActions,
690+
/*required*/ int/*!*/ id,
691+
/*required*/ int/*!*/ flags,
692+
/*required*/ int/*!*/ actions,
693+
/*required*/ int/*!*/ maxValueLength,
694+
/*required*/ int/*!*/ currentValueLength,
695+
/*required*/ int/*!*/ textSelectionBase,
696+
/*required*/ int/*!*/ textSelectionExtent,
697+
/*required*/ int/*!*/ platformViewId,
698+
/*required*/ int/*!*/ scrollChildren,
699+
/*required*/ int/*!*/ scrollIndex,
700+
/*required*/ double/*!*/ scrollPosition,
701+
/*required*/ double/*!*/ scrollExtentMax,
702+
/*required*/ double/*!*/ scrollExtentMin,
703+
/*required*/ double/*!*/ elevation,
704+
/*required*/ double/*!*/ thickness,
705+
/*required*/ Rect/*!*/ rect,
706+
/*required*/ String/*!*/ label,
707+
/*required*/ String/*!*/ hint,
708+
/*required*/ String/*!*/ value,
709+
/*required*/ String/*!*/ increasedValue,
710+
/*required*/ String/*!*/ decreasedValue,
711+
TextDirection/*?*/ textDirection,
712+
/*required*/ Float64List/*!*/ transform,
713+
/*required*/ Int32List/*!*/ childrenInTraversalOrder,
714+
/*required*/ Int32List/*!*/ childrenInHitTestOrder,
715+
/*required*/ Int32List/*!*/ additionalActions,
713716
}) {
717+
assert(id != null);
718+
assert(flags != null);
719+
assert(actions != null);
720+
assert(maxValueLength != null);
721+
assert(currentValueLength != null);
722+
assert(textSelectionBase != null);
723+
assert(textSelectionExtent != null);
724+
assert(platformViewId != null);
725+
assert(scrollChildren != null);
726+
assert(scrollIndex != null);
727+
assert(scrollPosition != null);
728+
assert(scrollExtentMax != null);
729+
assert(scrollExtentMin != null);
730+
assert(elevation != null);
731+
assert(thickness != null);
732+
assert(rect != null);
733+
assert(label != null);
734+
assert(hint != null);
735+
assert(value != null);
736+
assert(increasedValue != null);
737+
assert(decreasedValue != null);
738+
assert(transform != null);
739+
assert(childrenInTraversalOrder != null);
740+
assert(childrenInHitTestOrder != null);
741+
assert(additionalActions != null);
714742
assert(_matrix4IsValid(transform));
715-
assert(
716-
scrollChildren == 0 || scrollChildren == null || (scrollChildren > 0 && childrenInHitTestOrder != null),
717-
'If a node has scrollChildren, it must have childrenInHitTestOrder',
718-
);
719743
_updateNode(
720744
id,
721745
flags,
@@ -749,35 +773,35 @@ class SemanticsUpdateBuilder extends NativeFieldWrapperClass2 {
749773
);
750774
}
751775
void _updateNode(
752-
int id,
753-
int flags,
754-
int actions,
755-
int maxValueLength,
756-
int currentValueLength,
757-
int textSelectionBase,
758-
int textSelectionExtent,
759-
int platformViewId,
760-
int scrollChildren,
761-
int scrollIndex,
762-
double scrollPosition,
763-
double scrollExtentMax,
764-
double scrollExtentMin,
765-
double left,
766-
double top,
767-
double right,
768-
double bottom,
769-
double elevation,
770-
double thickness,
771-
String label,
772-
String hint,
773-
String value,
774-
String increasedValue,
775-
String decreasedValue,
776-
int textDirection,
777-
Float64List transform,
778-
Int32List childrenInTraversalOrder,
779-
Int32List childrenInHitTestOrder,
780-
Int32List additionalActions,
776+
int/*!*/ id,
777+
int/*!*/ flags,
778+
int/*!*/ actions,
779+
int/*!*/ maxValueLength,
780+
int/*!*/ currentValueLength,
781+
int/*!*/ textSelectionBase,
782+
int/*!*/ textSelectionExtent,
783+
int/*!*/ platformViewId,
784+
int/*!*/ scrollChildren,
785+
int/*!*/ scrollIndex,
786+
double/*!*/ scrollPosition,
787+
double/*!*/ scrollExtentMax,
788+
double/*!*/ scrollExtentMin,
789+
double/*!*/ left,
790+
double/*!*/ top,
791+
double/*!*/ right,
792+
double/*!*/ bottom,
793+
double/*!*/ elevation,
794+
double/*!*/ thickness,
795+
String/*!*/ label,
796+
String/*!*/ hint,
797+
String/*!*/ value,
798+
String/*!*/ increasedValue,
799+
String/*!*/ decreasedValue,
800+
int/*!*/ textDirection,
801+
Float64List/*!*/ transform,
802+
Int32List/*!*/ childrenInTraversalOrder,
803+
Int32List/*!*/ childrenInHitTestOrder,
804+
Int32List/*!*/ additionalActions,
781805
) native 'SemanticsUpdateBuilder_updateNode';
782806

783807
/// Update the custom semantics action associated with the given `id`.

lib/web_ui/lib/src/ui/semantics.dart

Lines changed: 52 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -667,35 +667,59 @@ class SemanticsUpdateBuilder {
667667
/// The `transform` is a matrix that maps this node's coordinate system into
668668
/// its parent's coordinate system.
669669
void updateNode({
670-
int id,
671-
int flags,
672-
int actions,
673-
int maxValueLength,
674-
int currentValueLength,
675-
int textSelectionBase,
676-
int textSelectionExtent,
677-
int platformViewId,
678-
int scrollChildren,
679-
int scrollIndex,
680-
double scrollPosition,
681-
double scrollExtentMax,
682-
double scrollExtentMin,
683-
double elevation,
684-
double thickness,
685-
Rect rect,
686-
String label,
687-
String hint,
688-
String value,
689-
String increasedValue,
690-
String decreasedValue,
691-
TextDirection textDirection,
692-
Float64List transform,
693-
Int32List childrenInTraversalOrder,
694-
Int32List childrenInHitTestOrder,
695-
Int32List additionalActions,
670+
/*required*/ int/*!*/ id,
671+
/*required*/ int/*!*/ flags,
672+
/*required*/ int/*!*/ actions,
673+
/*required*/ int/*!*/ maxValueLength,
674+
/*required*/ int/*!*/ currentValueLength,
675+
/*required*/ int/*!*/ textSelectionBase,
676+
/*required*/ int/*!*/ textSelectionExtent,
677+
/*required*/ int/*!*/ platformViewId,
678+
/*required*/ int/*!*/ scrollChildren,
679+
/*required*/ int/*!*/ scrollIndex,
680+
/*required*/ double/*!*/ scrollPosition,
681+
/*required*/ double/*!*/ scrollExtentMax,
682+
/*required*/ double/*!*/ scrollExtentMin,
683+
/*required*/ double/*!*/ elevation,
684+
/*required*/ double/*!*/ thickness,
685+
/*required*/ Rect/*!*/ rect,
686+
/*required*/ String/*!*/ label,
687+
/*required*/ String/*!*/ hint,
688+
/*required*/ String/*!*/ value,
689+
/*required*/ String/*!*/ increasedValue,
690+
/*required*/ String/*!*/ decreasedValue,
691+
TextDirection/*?*/ textDirection,
692+
/*required*/ Float64List/*!*/ transform,
693+
/*required*/ Int32List/*!*/ childrenInTraversalOrder,
694+
/*required*/ Int32List/*!*/ childrenInHitTestOrder,
695+
/*required*/ Int32List/*!*/ additionalActions,
696696
}) {
697-
if (transform.length != 16)
698-
throw ArgumentError('transform argument must have 16 entries.');
697+
assert(id != null);
698+
assert(flags != null);
699+
assert(actions != null);
700+
assert(maxValueLength != null);
701+
assert(currentValueLength != null);
702+
assert(textSelectionBase != null);
703+
assert(textSelectionExtent != null);
704+
assert(platformViewId != null);
705+
assert(scrollChildren != null);
706+
assert(scrollIndex != null);
707+
assert(scrollPosition != null);
708+
assert(scrollExtentMax != null);
709+
assert(scrollExtentMin != null);
710+
assert(elevation != null);
711+
assert(thickness != null);
712+
assert(rect != null);
713+
assert(label != null);
714+
assert(hint != null);
715+
assert(value != null);
716+
assert(increasedValue != null);
717+
assert(decreasedValue != null);
718+
assert(transform != null);
719+
assert(childrenInTraversalOrder != null);
720+
assert(childrenInHitTestOrder != null);
721+
assert(additionalActions != null);
722+
assert(transform.length == 16, 'transform argument must have 16 entries.');
699723
_nodeUpdates.add(engine.SemanticsNodeUpdate(
700724
id: id,
701725
flags: flags,

0 commit comments

Comments
 (0)