TextPosition class Null safety

A position in a string of text.

A TextPosition can be used to locate a position in a string in code (using the offset property), and it can also be used to locate the same position visually in a rendered string of text (using offset and, when needed to resolve ambiguity, affinity).

The location of an offset in a rendered string is ambiguous in two cases. One happens when rendered text is forced to wrap. In this case, the offset where the wrap occurs could visually appear either at the end of the first line or the beginning of the second line. The second way is with bidirectional text. An offset at the interface between two different text directions could have one of two locations in the rendered text.

See the documentation for TextAffinity for more information on how TextAffinity disambiguates situations like these.

Constructors

TextPosition({required int offset, TextAffinity affinity = TextAffinity.downstream})
Creates an object representing a particular position in a string.
const

Properties

affinity TextAffinity
Disambiguates cases where the position in the string given by offset could represent two different visual positions in the rendered text. For example, this can happen when text is forced to wrap, or when one string of text is rendered with multiple text directions.
final
hashCode int
The hash code for this object.
read-onlyoverride
offset int
The index of the character that immediately follows the position in the string representation of the text.
final
runtimeType Type
A representation of the runtime type of the object.
read-onlyinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
inherited
toString() String
A string representation of this object.
override

Operators

operator ==(Object other) bool
The equality operator.
override