extractMentions function

List<String> extractMentions(
  1. String value
)

Extract mentions (@username) from the text

Implementation

List<String> extractMentions(String value) {
  const decoratedTextColor = Colors.purple;
  final detector = Detector(
      textStyle: const TextStyle(),
      decoratedStyle: const TextStyle(color: decoratedTextColor),
      decorateAtSign: true);
  final detections = detector.getDetections(value);
  final taggedDetections = detections
      .where((detection) => detection.style!.color == decoratedTextColor)
      .toList();
  final result = taggedDetections
      .map((decoration) => decoration.range.textInside(value).trim())
      .where((text) => text.startsWith('@'))
      .toList();
  return result;
}