BarrageSendWidget
) and the display barrage messages Widget (BarrageDisplayWidget
):BarrageSendWidget
: The send barrage messages Widget, which can bring up the input interface when clicked.BarrageDisplayWidget
: After receiving barrage messages, it will display the barrage messages on this Widget.BarrageSendWidget | BarrageDisplayWidget | Effect of accessing the barrage component in LiveKit |
| | |
dependencies:flutter:sdk: flutterflutter_localizations:sdk: flutterintl: ^0.19.0# Add local dependency of barragebarrage:path: ../barrage
BarrageSendController _sendController = BarrageSendController(roomId: "liveRoomId", /// liveRoomId Replace with your live room IDownerId: "liveOwnerId", /// liveOwnerId Replace with your live room anchor IDselfUserId: "selfUserId", /// selfUserId Replace with your current logged-in user IDselfName: "selfUserName"; /// selfUserName Replace with your current logged-in user nicknameBarrageSendWidget(controller: _sendController);
BarrageDisplayController _displayController = BarrageDisplayController(roomId: "liveRoomId", /// liveRoomId Replace with your live room IDownerId: "liveOwnerId", /// liveOwnerId Replace with your live room anchor IDselfUserId: "selfUserId", /// selfUserId Replace with your current logged-in user IDselfName: "selfUserName"; /// selfUserName Replace with your current logged-in user nicknameBarrageDisplayWidget(controller: _displayController);
BarrageUser barrageUser = BarrageUser();barrageUser.userId = "enterRoomUserId"; /// UserId information displayed on the barrage.barrageUser.userName = "enterRoomUserName"; /// Nickname information displayed on the barragebarrageUser.avatarUrl = "enterRoomUserAvatar"; /// Avatar information displayed on the barragebarrageUser.level = "66"; /// Level information displayed on the barrageBarrage barrage = Barrage();barrage.user = barrageUser;barrage.content = "enter the room"; /// Text content displayed on the barrage_displayController.insertMessage(barrage);
/// 1. Define a custom barrage item builderclass GiftBarrageItemBuilder extends CustomBarrageBuilder {@overrideWidget buildWidget(BuildContext context, Barrage barrage) { /// Customize the Widget when `shouldCustomizeBarrageItem` returns truereturn const Text(barrage.content,style: TextStyle(fontSize: 18, fontWeight: FontWeight.w700, color: Colors.red),);}@overridebool shouldCustomizeBarrageItem(Barrage barrage) { /// Determine if the current barrage message needs customization based on the data model of the barrage messageif (barrage.extInfo.keys.isNotEmpty) {return true;}return false;}}/// 2. Set `setCustomBarrageBuilder` for `BarrageDisplayWidget`_displayController.setCustomBarrageBuilder(GiftBarrageItemBuilder());
Was this page helpful?