getMessage method

List<Widget> getMessage(
  1. BuildContext context
)

Implementation

List<Widget> getMessage(BuildContext context) {
  if (message.mentions != null && message.mentions!.isNotEmpty) {
    String stringRegex = r'([\s\S]*)';
    String stringMentionRegex = '';
    for (final Mention mention in message.mentions!) {
      stringRegex += '(${mention.title})' r'([\s\S]*)';
      stringMentionRegex += stringMentionRegex.isEmpty
          ? '(${mention.title})'
          : '|(${mention.title})';
    }
    final RegExp mentionRegex = RegExp(stringMentionRegex);
    final RegExp regexp = RegExp(stringRegex);

    RegExpMatch? match = regexp.firstMatch(message.text);
    if (match != null) {
      List<Widget> res = <Widget>[];
      match
          .groups(List<int>.generate(match.groupCount, (int i) => i + 1))
          .forEach((String? part) {
        Mention? mention;
        if (mentionRegex.hasMatch(part!)) {
          try {
            mention = message.mentions?.firstWhere(
              (Mention m) => m.title == part,
            );
          } catch (e) {
            // There is no mention
          }
        }
        if (mention != null) {
          res.add(getMention(context, mention));
        } else {
          res.add(getParsePattern(context, part, message.isMarkdown));
        }
      });
      if (res.isNotEmpty) {
        return res;
      }
    }
  }
  return <Widget>[getParsePattern(context, message.text, message.isMarkdown)];
}