buildWidget method

  1. @override
Widget buildWidget(
  1. BuildContext context,
  2. Barrage barrage
)
override

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: Text.rich(
          TextSpan(
            children: [
              TextSpan(
                text: senderUserName,
                style: const TextStyle(
                    fontSize: 12,
                    fontWeight: FontWeight.w700,
                    color: LiveColors.barrageUserNameColor),
              ),
              const TextSpan(text: ' '),
              TextSpan(
                text: LiveKitLocalizations.of(context)!.common_sent,
                style: const TextStyle(
                    fontSize: 12,
                    fontWeight: FontWeight.w700,
                    color: Colors.white),
              ),
              const TextSpan(text: ' '),
              TextSpan(
                text: receiverUserName,
                style: const TextStyle(
                    fontSize: 12,
                    fontWeight: FontWeight.w700,
                    color: LiveColors.barrageUserNameColor),
              ),
              const TextSpan(text: ' '),
              TextSpan(
                text: giftName,
                style: TextStyle(
                    fontSize: 12,
                    fontWeight: FontWeight.w700,
                    color: giftMessageColor[Random().nextInt(7)]),
              ),
              const TextSpan(text: ' '),
              WidgetSpan(
                alignment: PlaceholderAlignment.middle,
                child: CachedNetworkImage(
                  width: 13,
                  height: 13,
                  imageUrl: giftUrl,
                  fit: BoxFit.fitWidth,
                  placeholder: (context, url) => _buildDefaultGift(),
                  errorWidget: (context, url, error) => _buildDefaultGift(),
                ),
              ),
              const TextSpan(text: ' '),
              TextSpan(
                text: "x$giftCount",
                style: const TextStyle(
                    fontSize: 12,
                    fontWeight: FontWeight.w700,
                    color: Colors.white),
              ),
            ],
          ),
        ),
      ),
    ],
  );
}