getDetectedTextSpanWithExtraChild static method
TextSpan
getDetectedTextSpanWithExtraChild(
{
})
Implementation
static TextSpan getDetectedTextSpanWithExtraChild(
{required TextStyle decoratedStyle,
required TextStyle basicStyle,
required String source,
required RegExp detectionRegExp,
Function(String)? onTap,
bool decorateAtSign = false,
List<InlineSpan>? children}) {
final detections = source.toDetections(
detectedStyle: decoratedStyle,
textStyle: basicStyle,
detectionRegExp: detectionRegExp,
);
if (detections.isEmpty) {
// return TextSpan(text: source, style: basicStyle);
return TextSpan(
style: basicStyle,
text: source,
children: children,
);
} else {
detections.sort();
List<InlineSpan> 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();
span.addAll(children!);
return TextSpan(children: span);
}
}