dartclass SearchUtils { static TextStyle _active = TextStyle( color: RcTheme.rcColor.primary00CCA9, fontSize:RcTheme.rcColor.fontSize18, ); static TextStyle _off = TextStyle( color: RcTheme.rcColor.primary303133, fontSize:RcTheme.rcColor.fontSize18, ); /// 获取高亮关键字文本 static List<InlineSpan> getTitle(String source, String keyword, {TextStyle activeStyle,TextStyle offStyle}) { print("activeStyle = $activeStyle"); activeStyle = activeStyle??_active; offStyle = offStyle??_off; List<InlineSpan> list = []; List<String> sourceList = []; List<String> temp = source?.split(keyword); temp?.forEach((s) { sourceList.add(s); sourceList.add(keyword); }); if (sourceList.length > 0) sourceList.removeLast(); sourceList?.forEach((v) { if(v.isEmpty) { return; } if (v == keyword) { list.add(TextSpan( text: keyword, style: activeStyle ),); } else { list.add(TextSpan( text: v, style: offStyle ),); } }); return list; } }
本文作者:还是夸张一点
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!