opt: 评论框优化

This commit is contained in:
guozhigq
2024-04-26 23:46:54 +08:00
parent 23e2e83636
commit d60bc7fa45
6 changed files with 88 additions and 71 deletions

View File

@ -22,19 +22,14 @@ class ReplyHttp {
return {
'status': true,
'data': ReplyData.fromJson(res.data['data']),
'code': 200,
};
} else {
Map errMap = {
-400: '请求错误',
-404: '无此项',
12002: '当前页面评论功能已关闭',
12009: '评论主体的type不合法',
12061: 'UP主已关闭评论区',
};
return {
'status': false,
'date': [],
'msg': errMap[res.data['code']] ?? res.data['message'],
'code': res.data['code'],
'msg': res.data['message'],
};
}
}

View File

@ -25,6 +25,7 @@ class DynamicDetailController extends GetxController {
RxString sortTypeTitle = ReplySortType.time.titles.obs;
RxString sortTypeLabel = ReplySortType.time.labels.obs;
Box setting = GStrorage.setting;
RxInt replyReqCode = 200.obs;
@override
void onInit() {
@ -84,6 +85,7 @@ class DynamicDetailController extends GetxController {
replyList.addAll(replies);
}
}
replyReqCode.value = res['code'];
isLoadingMore = false;
return res;
}

View File

@ -369,35 +369,40 @@ class _DynamicDetailPageState extends State<DynamicDetailPage>
curve: Curves.easeInOut,
),
),
child: FloatingActionButton(
heroTag: null,
onPressed: () {
feedBack();
showModalBottomSheet(
context: context,
isScrollControlled: true,
builder: (BuildContext context) {
return VideoReplyNewDialog(
oid: _dynamicDetailController.oid ??
IdUtils.bv2av(Get.parameters['bvid']!),
root: 0,
parent: 0,
replyType: ReplyType.values[replyType],
);
},
).then(
(value) => {
// 完成评论,数据添加
if (value != null && value['data'] != null)
{
_dynamicDetailController.replyList.add(value['data']),
_dynamicDetailController.acount.value++
}
},
);
},
tooltip: '评论动态',
child: const Icon(Icons.reply),
child: Obx(
() => _dynamicDetailController.replyReqCode.value == 12061
? const SizedBox()
: FloatingActionButton(
heroTag: null,
onPressed: () {
feedBack();
showModalBottomSheet(
context: context,
isScrollControlled: true,
builder: (BuildContext context) {
return VideoReplyNewDialog(
oid: _dynamicDetailController.oid ??
IdUtils.bv2av(Get.parameters['bvid']!),
root: 0,
parent: 0,
replyType: ReplyType.values[replyType],
);
},
).then(
(value) => {
// 完成评论,数据添加
if (value != null && value['data'] != null)
{
_dynamicDetailController.replyList
.add(value['data']),
_dynamicDetailController.acount.value++
}
},
);
},
tooltip: '评论动态',
child: const Icon(Icons.reply),
),
),
),
);

View File

@ -37,6 +37,7 @@ class VideoReplyController extends GetxController {
RxString sortTypeLabel = ReplySortType.time.labels.obs;
Box setting = GStrorage.setting;
RxInt replyReqCode = 200.obs;
@override
void onInit() {
@ -106,6 +107,7 @@ class VideoReplyController extends GetxController {
replyList.addAll(replies);
}
}
replyReqCode.value = res['code'];
isLoadingMore = false;
return res;
}

View File

@ -277,32 +277,39 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
parent: fabAnimationCtr,
curve: Curves.easeInOut,
)),
child: FloatingActionButton(
heroTag: null,
onPressed: () {
feedBack();
showModalBottomSheet(
context: context,
isScrollControlled: true,
builder: (BuildContext context) {
return VideoReplyNewDialog(
oid: _videoReplyController.aid ??
IdUtils.bv2av(Get.parameters['bvid']!),
root: 0,
parent: 0,
replyType: ReplyType.video,
);
},
).then(
(value) => {
// 完成评论,数据添加
if (value != null && value['data'] != null)
{_videoReplyController.replyList.add(value['data'])}
},
);
},
tooltip: '发表评论',
child: const Icon(Icons.reply),
child: Obx(
() => _videoReplyController.replyReqCode.value == 12061
? const SizedBox()
: FloatingActionButton(
heroTag: null,
onPressed: () {
feedBack();
showModalBottomSheet(
context: context,
isScrollControlled: true,
builder: (BuildContext context) {
return VideoReplyNewDialog(
oid: _videoReplyController.aid ??
IdUtils.bv2av(Get.parameters['bvid']!),
root: 0,
parent: 0,
replyType: ReplyType.video,
);
},
).then(
(value) => {
// 完成评论,数据添加
if (value != null && value['data'] != null)
{
_videoReplyController.replyList
.add(value['data'])
}
},
);
},
tooltip: '发表评论',
child: const Icon(Icons.reply),
),
),
),
),

View File

@ -43,6 +43,7 @@ class _VideoReplyNewDialogState extends State<VideoReplyNewDialog>
String toolbarType = 'input';
RxBool isForward = false.obs;
RxBool showForward = false.obs;
RxString message = ''.obs;
@override
void initState() {
@ -80,15 +81,15 @@ class _VideoReplyNewDialogState extends State<VideoReplyNewDialog>
Future submitReplyAdd() async {
feedBack();
String message = _replyContentController.text;
// String message = _replyContentController.text;
var result = await VideoHttp.replyAdd(
type: widget.replyType ?? ReplyType.video,
oid: widget.oid!,
root: widget.root!,
parent: widget.parent!,
message: widget.replyItem != null && widget.replyItem!.root != 0
? ' 回复 @${widget.replyItem!.member!.uname!} : $message'
: message,
? ' 回复 @${widget.replyItem!.member!.uname!} : ${message.value}'
: message.value,
);
if (result['status']) {
SmartDialog.showToast(result['data']['success_toast']);
@ -100,7 +101,7 @@ class _VideoReplyNewDialogState extends State<VideoReplyNewDialog>
if (isForward.value) {
await DynamicsHttp.dynamicCreate(
mid: 0,
rawText: message,
rawText: message.value,
oid: widget.oid!,
scene: 5,
);
@ -188,7 +189,7 @@ class _VideoReplyNewDialogState extends State<VideoReplyNewDialog>
autovalidateMode: AutovalidateMode.onUserInteraction,
child: TextField(
controller: _replyContentController,
minLines: 1,
minLines: 3,
maxLines: null,
autofocus: false,
focusNode: replyContentFocusNode,
@ -199,6 +200,9 @@ class _VideoReplyNewDialogState extends State<VideoReplyNewDialog>
fontSize: 14,
)),
style: Theme.of(context).textTheme.bodyLarge,
onChanged: (text) {
message.value = text;
},
),
),
),
@ -267,9 +271,11 @@ class _VideoReplyNewDialogState extends State<VideoReplyNewDialog>
const Spacer(),
SizedBox(
height: 36,
child: FilledButton(
onPressed: () => submitReplyAdd(),
child: const Text('发送'),
child: Obx(
() => FilledButton(
onPressed: message.isNotEmpty ? submitReplyAdd : null,
child: const Text('发送'),
),
),
),
],