extent property Null safety

TextPosition extent

The position at which the selection terminates.

When the user uses the arrow keys to adjust the selection, this is the value that changes. Similarly, if the current theme paints a caret on one side of the selection, this is the location at which to paint the caret.

The TextAffinity of the resulting TextPosition is based on the relative logical position in the text to the other selection endpoint:

Might be larger than, smaller than, or equal to base.

Implementation

TextPosition get extent {
  final TextAffinity affinity;
  if (!isValid || baseOffset == extentOffset) {
    affinity = this.affinity;
  } else if (baseOffset < extentOffset) {
    affinity = TextAffinity.upstream;
  } else {
    affinity = TextAffinity.downstream;
  }
  return TextPosition(offset: extentOffset, affinity: affinity);
}