mod: 输入框样式

This commit is contained in:
guozhigq
2024-08-22 23:57:11 +08:00
parent 44910b35d9
commit 844db213a5
2 changed files with 75 additions and 4 deletions

View File

@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:convert'; import 'dart:convert';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
@ -42,6 +43,8 @@ class LiveRoomController extends GetxController {
DanmakuController? danmakuController; DanmakuController? danmakuController;
// 输入控制器 // 输入控制器
TextEditingController inputController = TextEditingController(); TextEditingController inputController = TextEditingController();
// 加入直播间提示
RxMap<String, String> joinRoomTip = {'userName': '', 'message': ''}.obs;
@override @override
void onInit() { void onInit() {
@ -176,7 +179,29 @@ class LiveRoomController extends GetxController {
onMessageCb: (message) { onMessageCb: (message) {
final List<LiveMessageModel>? liveMsg = final List<LiveMessageModel>? liveMsg =
LiveUtils.decodeMessage(message); LiveUtils.decodeMessage(message);
if (liveMsg != null) { if (liveMsg != null && liveMsg.isNotEmpty) {
if (liveMsg.first.type == LiveMessageType.online) {
print('当前直播间人气:${liveMsg.first.data}');
} 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) {
if (liveMsg[index].type == LiveMessageType.join ||
liveMsg[index].type == LiveMessageType.follow) {
joinRoomTip.value = {
'userName': liveMsg[index].userName,
'message': liveMsg[index].message!,
};
}
index++;
} else {
timer.cancel();
}
});
return;
}
// 过滤出聊天消息 // 过滤出聊天消息
var chatMessages = var chatMessages =
liveMsg.where((msg) => msg.type == LiveMessageType.chat).toList(); liveMsg.where((msg) => msg.type == LiveMessageType.chat).toList();

View File

@ -179,6 +179,7 @@ class _LiveRoomPageState extends State<LiveRoomPage>
), ),
), ),
Column( Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
AppBar( AppBar(
centerTitle: false, centerTitle: false,
@ -263,6 +264,49 @@ class _LiveRoomPageState extends State<LiveRoomPage>
_liveRoomController, _liveRoomController,
_scrollController, _scrollController,
), ),
// Container(
// padding: const EdgeInsets.only(
// left: 14, right: 14, top: 4, bottom: 4),
// margin: const EdgeInsets.only(
// bottom: 6,
// left: 14,
// ),
// decoration: BoxDecoration(
// color: Colors.grey.withOpacity(0.1),
// borderRadius: const BorderRadius.all(Radius.circular(20)),
// ),
// child: Obx(
// () => AnimatedSwitcher(
// duration: const Duration(milliseconds: 300),
// transitionBuilder:
// (Widget child, Animation<double> animation) {
// return FadeTransition(opacity: animation, child: child);
// },
// child: Text.rich(
// key:
// ValueKey(_liveRoomController.joinRoomTip['userName']),
// TextSpan(
// style: const TextStyle(color: Colors.white),
// children: [
// TextSpan(
// text:
// '${_liveRoomController.joinRoomTip['userName']} ',
// style: TextStyle(
// color: Colors.white.withOpacity(0.6),
// ),
// ),
// TextSpan(
// text:
// '${_liveRoomController.joinRoomTip['message']}',
// style: const TextStyle(color: Colors.white),
// ),
// ],
// ),
// ),
// ),
// ),
// ),
const SizedBox(height: 10),
// 弹幕输入框 // 弹幕输入框
Container( Container(
padding: EdgeInsets.only( padding: EdgeInsets.only(
@ -271,7 +315,8 @@ class _LiveRoomPageState extends State<LiveRoomPage>
top: 4, top: 4,
bottom: MediaQuery.of(context).padding.bottom + 20), bottom: MediaQuery.of(context).padding.bottom + 20),
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.black.withOpacity(0.5), color: Colors.grey.withOpacity(0.1),
borderRadius: const BorderRadius.all(Radius.circular(20)),
border: Border( border: Border(
top: BorderSide( top: BorderSide(
color: Colors.white.withOpacity(0.1), color: Colors.white.withOpacity(0.1),
@ -280,6 +325,7 @@ class _LiveRoomPageState extends State<LiveRoomPage>
), ),
child: Row( child: Row(
children: [ children: [
const SizedBox(width: 4),
Expanded( Expanded(
child: TextField( child: TextField(
controller: _liveRoomController.inputController, controller: _liveRoomController.inputController,
@ -309,10 +355,10 @@ class _LiveRoomPageState extends State<LiveRoomPage>
// 定位 快速滑动到底部 // 定位 快速滑动到底部
Positioned( Positioned(
right: 20, right: 20,
bottom: MediaQuery.of(context).padding.bottom + 20, bottom: MediaQuery.of(context).padding.bottom + 80,
child: SlideTransition( child: SlideTransition(
position: Tween<Offset>( position: Tween<Offset>(
begin: const Offset(0, 2), begin: const Offset(0, 4),
end: const Offset(0, 0), end: const Offset(0, 0),
).animate(CurvedAnimation( ).animate(CurvedAnimation(
parent: fabAnimationCtr, parent: fabAnimationCtr,