buildTextSpan method

  1. @override
TextSpan buildTextSpan({
  1. required BuildContext context,
  2. TextStyle? style,
  3. required 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 context, TextStyle? style, required bool withComposing}) {
  convertedText = "";
  pureText = value.text;
  final List<InlineSpan> children = [];
  int charCount = 0;
  List<ValidatedData> validatedDataList = validate(value.text);
  for (var data in validatedDataList) {
    if (data.canConvertToChip) {
      charCount++;
      children.add(TextSpan(style: style!.merge(TextStyle(color: Colors.black)), children: [
        WidgetSpan(
            baseline: TextBaseline.ideographic,
            alignment: PlaceholderAlignment.middle,
            child: Container(
              child: chipBuilder(context, state, data.value, this),
            )),
      ]));
    } else {
      charCount = charCount + data.value.length;
      children.add(TextSpan(text: data.value, style: style));
    }
  }
  return TextSpan(
      text: value.text.substring(0, value.text.length - (charCount)),
      style: TextStyle(color: Colors.transparent, fontSize: 0),
      children: children);
}