buildTextSpan method

  1. @override
TextSpan buildTextSpan({
  1. required BuildContext context,
  2. TextStyle? style,
  3. bool? withComposing,
})
override

Builds TextSpan from current editing value.

By default makes text in composing range appear as underlined. Descendants can override this method to customize appearance of text.

Implementation

@override
TextSpan buildTextSpan({
  required BuildContext context,
  TextStyle? style,
  bool? withComposing,
}) {
  final children = <InlineSpan>[];
  final list = text.split('\n');

  for (int k = 0; k < list.length; k++) {
    final el = list[k];
    final number = int.parse(el);
    var textSpan = TextSpan(text: el, style: style);

    if (lineNumberBuilder != null) {
      textSpan = lineNumberBuilder!(number, style);
    }

    children.add(textSpan);
    if (k < list.length - 1) {
      children.add(const TextSpan(text: '\n'));
    }
  }

  return TextSpan(children: children, style: style);
}