cardBubbleText function
- String content,
- MessageCard? card, {
- String? intro,
The text to show in the bubble above card, given the message content.
The gateway stores, for email, push and other channels, an optional intro
line followed by a plain-text summary of the card. Under a product, order
or payment card the SDK draws, only the intro is kept: intro (the
gateway's metadata.intro) when given, else ProductCard.intro, the lines
before "Đơn hàng {code}", or the lines before the "Thanh toán…" line that
is followed by "Quét mã VietQR…". When none is found the result is empty
and the bubble is hidden. Quick replies, ratings and no card keep
content as is.
Implementation
String cardBubbleText(String content, MessageCard? card, {String? intro}) {
final lines = content.split('\n');
String before(int index) => index < 0 ? '' : lines.sublist(0, index).join('\n').trim();
switch (card) {
case null || QuickRepliesCard() || CsatCard():
return content;
case _ when intro != null:
return intro.trim();
case ProductCard(:final intro):
return intro?.trim() ?? '';
case OrderCard(:final code):
return before(lines.indexWhere((l) => l.trim() == 'Đơn hàng $code'));
case PaymentCard():
for (var i = 0; i + 1 < lines.length; i++) {
if (lines[i].startsWith('Thanh toán') && lines[i + 1].startsWith('Quét mã VietQR')) return before(i);
}
return '';
}
}