buildWidget method

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

Implementation

@override
Widget buildWidget(BuildContext context, Barrage barrage) {
  String receiverUserId = barrage.extInfo[Constants.keyGiftReceiverUserId];
  String receiverUserName =
      barrage.extInfo[Constants.keyGiftReceiverUsername];
  String giftUrl = barrage.extInfo[Constants.keyGiftImage];
  String giftName = barrage.extInfo[Constants.keyGiftName];
  int giftCount = barrage.extInfo[Constants.keyGiftCount];
  String senderUserId = barrage.user.userId;
  String senderUserName = barrage.user.userName;
  if (senderUserId == selfUserId) {
    senderUserName = LiveKitLocalizations.of(context)!.live_gift_me;
  }
  if (receiverUserId == selfUserId) {
    receiverUserName = LiveKitLocalizations.of(context)!.live_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: context.adapter.getWidth(4)),
            Text(
              senderUserName,
              style: const TextStyle(
                  fontSize: 12,
                  fontWeight: FontWeight.w700,
                  color: LiveColors.barrageUserNameColor),
            ),
            SizedBox(width: context.adapter.getWidth(4)),
            Text(
              LiveKitLocalizations.of(context)!.live_sent,
              style: const TextStyle(
                  fontSize: 12,
                  fontWeight: FontWeight.w700,
                  color: Colors.white),
            ),
            SizedBox(width: context.adapter.getWidth(4)),
            Text(
              receiverUserName,
              style: const TextStyle(
                  fontSize: 12,
                  fontWeight: FontWeight.w700,
                  color: LiveColors.barrageUserNameColor),
            ),
            SizedBox(width: context.adapter.getWidth(4)),
            Text(
              giftName,
              style: TextStyle(
                  fontSize: 12,
                  fontWeight: FontWeight.w700,
                  color: giftMessageColor[Random().nextInt(7)]),
            ),
            SizedBox(width: context.adapter.getWidth(4)),
            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: context.adapter.getWidth(4)),
            Text(
              "x$giftCount",
              style: const TextStyle(
                  fontSize: 12,
                  fontWeight: FontWeight.w700,
                  color: Colors.white),
            ),
          ],
        ),
      ),
    ],
  );
}