getDetectedTextSpan static method
Returns textSpan with detected text
Used in DetectableText
Implementation
static TextSpan getDetectedTextSpan({
required TextStyle decoratedStyle,
required TextStyle basicStyle,
required String source,
required RegExp detectionRegExp,
Function(String)? onTap,
bool decorateAtSign = false,
}) {
final detections = source.toDetections(
detectedStyle: decoratedStyle,
textStyle: basicStyle,
detectionRegExp: detectionRegExp,
);
if (detections.isEmpty) {
return TextSpan(text: source, style: basicStyle);
} else {
detections.sort();
final span = detections
.asMap()
.map(
(index, item) {
TapGestureRecognizer? recognizer;
final decoration = detections[index];
if (decoration.style == decoratedStyle && onTap != null) {
recognizer = TapGestureRecognizer()
..onTap = () {
onTap(decoration.range.textInside(source).trim());
};
}
return MapEntry(
index,
TextSpan(
style: item.style,
text: item.range.textInside(source),
recognizer: (onTap == null) ? null : recognizer,
),
);
},
)
.values
.toList();
return TextSpan(children: span);
}
}