LineSplitter typedef
Signature of a function that splits a line of text into words that may be wrapped independently.
By default, lines are split at whitespace, which means that scripts without word separators (Chinese, Japanese, Korean...) are treated as a single word and can only be broken by the hard-splitting fallback, without any line breaking rule (no prohibition of closing punctuation at the beginning of a line, etc.).
Providing a custom splitter enables script-aware line wrapping, for instance breaking between CJK characters, or implementing the Unicode Line Breaking Algorithm (UAX #14):
RichText(
text: TextSpan(
text: '你好,世界',
// Each CJK character may wrap independently. Spaces are not inserted
// between the words, so the space width must be cleared.
style: TextStyle(font: myCjkFont, wordSpacing: 0),
),
lineSplitter: (line) => line.split(''),
);
Whitespace runs must be returned the same way String.split does (as empty strings) when they are expected to keep their width, so that the default behavior is preserved for mixed content.
Implementation
typedef LineSplitter = List<String> Function(String line);