PQText.regexRich constructor
PQText.regexRich(
- String text,
- RegExp regExp,
- TextStyle regExpStyle, {
- Key? key,
- TextDecoration? decoration,
- TextAlign textAlign = TextAlign.start,
- int? maxLines,
- Color? color = const Color(0xff000000),
- double fontSize = 17,
- String? fontFamily,
- FontWeight? fontWeight = FontWeight.normal,
- double? wordSpacing,
- double? letterSpacing,
- StrutStyle? strutStyle,
- TextOverflow? overflow = TextOverflow.ellipsis,
- double? textScaleFactor = 1,
- double? lineHeight,
通过正则去匹配文字,修改匹配成功的文本样式
Implementation
PQText.regexRich(
String text,
RegExp regExp,
TextStyle regExpStyle, {
Key? key,
this.decoration,
this.textAlign = TextAlign.start,
this.maxLines,
this.color = const Color(0xff000000),
this.fontSize = 17,
this.fontFamily,
this.fontWeight = FontWeight.normal,
this.wordSpacing,
this.letterSpacing,
this.strutStyle,
this.overflow = TextOverflow.ellipsis,
this.textScaleFactor = 1,
double? lineHeight,
}) : super(key: key) {
if (lineHeight != null) {
height = lineHeight / fontSize;
}
title = '';
final list = YHMatch.regex(regExp, text);
children = [];
if (list.isEmpty) {
title = text;
}
list.forEach((element) {
final start = element.highlight ? element.start + 1 : element.start;
final end = element.highlight ? element.end - 1 : element.end;
children!.add(TextSpan(
text: text.substring(start, end),
style: element.highlight ? regExpStyle : null,
));
});
}