mod: 直播弹幕开关
This commit is contained in:
@ -129,7 +129,7 @@ class _PlDanmakuState extends State<PlDanmaku> {
|
||||
// double initDuration = box.maxWidth / 12;
|
||||
return Obx(
|
||||
() => AnimatedOpacity(
|
||||
opacity: playerController.isOpenDanmu.value ? 1 : 1,
|
||||
opacity: playerController.isOpenDanmu.value ? 1 : 0,
|
||||
duration: const Duration(milliseconds: 100),
|
||||
child: DanmakuView(
|
||||
createdController: (DanmakuController e) async {
|
||||
|
@ -45,6 +45,8 @@ class LiveRoomController extends GetxController {
|
||||
TextEditingController inputController = TextEditingController();
|
||||
// 加入直播间提示
|
||||
RxMap<String, String> joinRoomTip = {'userName': '', 'message': ''}.obs;
|
||||
// 直播间弹幕开关 默认打开
|
||||
RxBool danmakuSwitch = true.obs;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
@ -69,6 +71,9 @@ class LiveRoomController extends GetxController {
|
||||
userId = userInfo.mid;
|
||||
}
|
||||
liveDanmakuInfo().then((value) => initSocket());
|
||||
danmakuSwitch.listen((p0) {
|
||||
plPlayerController.isOpenDanmu.value = p0;
|
||||
});
|
||||
}
|
||||
|
||||
playerInit(source) async {
|
||||
@ -87,6 +92,7 @@ class LiveRoomController extends GetxController {
|
||||
enableHA: true,
|
||||
autoplay: true,
|
||||
);
|
||||
plPlayerController.isOpenDanmu.value = danmakuSwitch.value;
|
||||
}
|
||||
|
||||
Future queryLiveInfo() async {
|
||||
@ -185,6 +191,7 @@ class LiveRoomController extends GetxController {
|
||||
} else if (liveMsg.first.type == LiveMessageType.join ||
|
||||
liveMsg.first.type == LiveMessageType.follow) {
|
||||
// 每隔一秒依次liveMsg中的每一项赋给activeUserName
|
||||
|
||||
int index = 0;
|
||||
Timer.periodic(const Duration(seconds: 2), (timer) {
|
||||
if (index < liveMsg.length) {
|
||||
@ -200,6 +207,7 @@ class LiveRoomController extends GetxController {
|
||||
timer.cancel();
|
||||
}
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
// 过滤出聊天消息
|
||||
@ -223,7 +231,9 @@ class LiveRoomController extends GetxController {
|
||||
}).toList();
|
||||
|
||||
// 添加到 danmakuController
|
||||
danmakuController?.addItems(danmakuItems);
|
||||
if (danmakuSwitch.value) {
|
||||
danmakuController?.addItems(danmakuItems);
|
||||
}
|
||||
}
|
||||
},
|
||||
onErrorCb: (e) {
|
||||
|
@ -325,7 +325,33 @@ class _LiveRoomPageState extends State<LiveRoomPage>
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const SizedBox(width: 4),
|
||||
SizedBox(
|
||||
width: 34,
|
||||
height: 34,
|
||||
child: Obx(
|
||||
() => IconButton(
|
||||
style: ButtonStyle(
|
||||
padding: MaterialStateProperty.all(EdgeInsets.zero),
|
||||
backgroundColor: MaterialStateProperty.resolveWith(
|
||||
(Set<MaterialState> states) {
|
||||
return Colors.grey.withOpacity(0.1);
|
||||
}),
|
||||
),
|
||||
onPressed: () {
|
||||
_liveRoomController.danmakuSwitch.value =
|
||||
!_liveRoomController.danmakuSwitch.value;
|
||||
},
|
||||
icon: Icon(
|
||||
_liveRoomController.danmakuSwitch.value
|
||||
? Icons.subtitles_outlined
|
||||
: Icons.subtitles_off_outlined,
|
||||
size: 19,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _liveRoomController.inputController,
|
||||
@ -340,11 +366,19 @@ class _LiveRoomPageState extends State<LiveRoomPage>
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () => _liveRoomController.sendMsg(),
|
||||
icon: const Icon(
|
||||
Icons.send,
|
||||
color: Colors.white,
|
||||
SizedBox(
|
||||
width: 34,
|
||||
height: 34,
|
||||
child: IconButton(
|
||||
style: ButtonStyle(
|
||||
padding: MaterialStateProperty.all(EdgeInsets.zero),
|
||||
),
|
||||
onPressed: () => _liveRoomController.sendMsg(),
|
||||
icon: const Icon(
|
||||
Icons.send,
|
||||
color: Colors.white,
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
@ -418,56 +452,62 @@ Widget buildMessageListUI(
|
||||
).createShader(bounds);
|
||||
},
|
||||
blendMode: BlendMode.dstIn,
|
||||
child: ListView.builder(
|
||||
controller: scrollController,
|
||||
itemCount: liveRoomController.messageList.length,
|
||||
itemBuilder: (context, index) {
|
||||
final LiveMessageModel liveMsgItem =
|
||||
liveRoomController.messageList[index];
|
||||
return Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey.withOpacity(0.1),
|
||||
borderRadius: const BorderRadius.all(Radius.circular(20)),
|
||||
),
|
||||
margin: EdgeInsets.only(
|
||||
top: index == 0 ? 20.0 : 0.0,
|
||||
bottom: 6.0,
|
||||
left: 14.0,
|
||||
right: 14.0,
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 3.0,
|
||||
horizontal: 10.0,
|
||||
),
|
||||
child: Text.rich(
|
||||
TextSpan(
|
||||
style: const TextStyle(color: Colors.white),
|
||||
children: [
|
||||
TextSpan(
|
||||
text: '${liveMsgItem.userName}: ',
|
||||
style: TextStyle(
|
||||
color: Colors.white.withOpacity(0.6),
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
// 键盘失去焦点
|
||||
FocusScope.of(context).requestFocus(FocusNode());
|
||||
},
|
||||
child: ListView.builder(
|
||||
controller: scrollController,
|
||||
itemCount: liveRoomController.messageList.length,
|
||||
itemBuilder: (context, index) {
|
||||
final LiveMessageModel liveMsgItem =
|
||||
liveRoomController.messageList[index];
|
||||
return Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey.withOpacity(0.1),
|
||||
borderRadius: const BorderRadius.all(Radius.circular(20)),
|
||||
),
|
||||
margin: EdgeInsets.only(
|
||||
top: index == 0 ? 20.0 : 0.0,
|
||||
bottom: 6.0,
|
||||
left: 14.0,
|
||||
right: 14.0,
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 3.0,
|
||||
horizontal: 10.0,
|
||||
),
|
||||
child: Text.rich(
|
||||
TextSpan(
|
||||
style: const TextStyle(color: Colors.white),
|
||||
children: [
|
||||
TextSpan(
|
||||
text: '${liveMsgItem.userName}: ',
|
||||
style: TextStyle(
|
||||
color: Colors.white.withOpacity(0.6),
|
||||
),
|
||||
recognizer: TapGestureRecognizer()
|
||||
..onTap = () {
|
||||
// 处理点击事件
|
||||
print('Text clicked');
|
||||
},
|
||||
),
|
||||
recognizer: TapGestureRecognizer()
|
||||
..onTap = () {
|
||||
// 处理点击事件
|
||||
print('Text clicked');
|
||||
},
|
||||
),
|
||||
TextSpan(
|
||||
children: [
|
||||
...buildMessageTextSpan(context, liveMsgItem)
|
||||
],
|
||||
// text: liveMsgItem.message,
|
||||
),
|
||||
],
|
||||
TextSpan(
|
||||
children: [
|
||||
...buildMessageTextSpan(context, liveMsgItem)
|
||||
],
|
||||
// text: liveMsgItem.message,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
Reference in New Issue
Block a user