buildNoTapHighlight static method

Widget buildNoTapHighlight({
  1. required String text,
  2. String highlightText = "",
  3. required TextStyle textStyle,
  4. required TextStyle highlightStyle,
  5. int maxLines = 1,
  6. TextOverflow overflow = TextOverflow.ellipsis,
})

Implementation

static Widget buildNoTapHighlight({
  required String text,
  String highlightText = "",
  required TextStyle textStyle,
  required TextStyle highlightStyle,
  int maxLines = 1,
  TextOverflow overflow = TextOverflow.ellipsis,
}) {
  if (highlightText.isEmpty) {
    return Text(text, maxLines: maxLines, overflow: overflow, style: textStyle);
  }

  List<TextSpan> spans = text.characters.map((char) {
    bool isHighlighted = highlightText.toLowerCase().contains(char.toLowerCase());
    return TextSpan(text: char, style: isHighlighted ? highlightStyle : textStyle);
  }).toList();

  return RichText(
    maxLines: maxLines,
    overflow: overflow,
    text: TextSpan(children: spans),
  );
}