RcTheme.rcColor对应为颜色,自己项目封装的主题色
class 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;
}
}