getHashtagsFromText static method

List<String> getHashtagsFromText({
  1. required String text,
})

Implementation

static List<String> getHashtagsFromText({
  required final String text,
}) {
  final result = <String>[];

  var thisText = text;

  while (thisText.contains('#')) {
    final hashIndex = thisText.indexOf('#');

    if (hashIndex != -1) {
      final newText = thisText.substring(hashIndex, thisText.length);

      final splittedText = newText.split(' ');
      if (splittedText.isNotEmpty) {
        final hashTagText = splittedText.first;

        result.add(hashTagText);
        thisText = thisText.replaceAll(hashTagText, '');
      }
    }
  }

  return result;
}