getAllEntityTexts method

List<String> getAllEntityTexts(
  1. MessageEntityType type
)

Extracts text for all entities of the specified type.

Unlike getEntityText which returns only the first match, this method returns all occurrences of the specified entity type.

Returns an empty list if no entities of the specified type are found.

Example:

// For message: "Check #flutter and #dart hashtags"
final hashtags = ctx.getAllEntityTexts(MessageEntityType.hashtag);
// Returns: ["flutter", "dart"]

Implementation

List<String> getAllEntityTexts(MessageEntityType type) {
  final entityData = _getEntityData();
  if (entityData == null) return [];

  return entityData.entities
      .where((e) => e.type == type)
      .map((entity) => _extractEntityText(entity, entityData.text, type))
      .where((text) => text != null)
      .cast<String>()
      .toList();
}