extractDetections function

List<String> extractDetections(
  1. String value,
  2. RegExp detectionRegExp
)

Extract detections from the text

Implementation

List<String> extractDetections(String value, RegExp detectionRegExp) {
  final decoratedTextColor = Colors.blue;
  final decorator = Detector(
    textStyle: TextStyle(),
    detectedStyle: TextStyle(color: decoratedTextColor),
    detectionRegExp: detectionRegExp,
  );
  final decorations = decorator.getDetections(value);
  final taggedDecorations = decorations
      .where((decoration) => decoration.style!.color == decoratedTextColor)
      .toList();
  final result = taggedDecorations.map((decoration) {
    final text = decoration.range.textInside(value);
    return text.trim();
  }).toList();
  return result;
}