buildWidget method
Implementation
@override
Widget buildWidget(BuildContext context, Barrage barrage) {
String receiverUserId = barrage.extensionInfo[Constants.keyGiftReceiverUserId] ?? '';
String receiverUserName =
barrage.extensionInfo[Constants.keyGiftReceiverUsername] ?? '';
String giftUrl = barrage.extensionInfo[Constants.keyGiftImage] ?? '';
String giftName = barrage.extensionInfo[Constants.keyGiftName] ?? '';
int giftCount = int.tryParse(barrage.extensionInfo[Constants.keyGiftCount] ?? '0') ?? 0;
String senderUserId = barrage.sender.userID;
String senderUserName = barrage.sender.userName;
if (senderUserId == selfUserId) {
senderUserName = LiveKitLocalizations.of(context)!.common_gift_me;
}
if (receiverUserId == selfUserId) {
receiverUserName = LiveKitLocalizations.of(context)!.common_gift_me;
}
return Wrap(
children: [
Container(
margin: const EdgeInsets.only(top: 3, bottom: 3),
padding: const EdgeInsets.only(left: 6, top: 4, right: 6, bottom: 4),
decoration: BoxDecoration(
color: LiveColors.notStandard40G1,
borderRadius: BorderRadius.circular(14),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
SizedBox(width: 4.width),
Text(
senderUserName,
style: const TextStyle(
fontSize: 12,
fontWeight: FontWeight.w700,
color: LiveColors.barrageUserNameColor),
),
SizedBox(width: 4.width),
Text(
LiveKitLocalizations.of(context)!.common_sent,
style: const TextStyle(
fontSize: 12,
fontWeight: FontWeight.w700,
color: Colors.white),
),
SizedBox(width: 4.width),
Text(
receiverUserName,
style: const TextStyle(
fontSize: 12,
fontWeight: FontWeight.w700,
color: LiveColors.barrageUserNameColor),
),
SizedBox(width: 4.width),
Text(
giftName,
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w700,
color: giftMessageColor[Random().nextInt(7)]),
),
SizedBox(width: 4.width),
Padding(
padding: const EdgeInsets.only(top: 3.0),
child: CachedNetworkImage(
width: 13,
height: 13,
imageUrl: giftUrl,
fit: BoxFit.fitWidth,
placeholder: (context, url) => _buildDefaultGift(),
errorWidget: (context, url, error) => _buildDefaultGift(),
),
),
SizedBox(width: 4.width),
Text(
"x$giftCount",
style: const TextStyle(
fontSize: 12,
fontWeight: FontWeight.w700,
color: Colors.white),
),
],
),
),
],
);
}