opt: onReply, onDelete

This commit is contained in:
bggRGjQaUbCoE
2024-09-12 20:55:13 +08:00
parent 93e8e14795
commit 1542f87722
9 changed files with 149 additions and 306 deletions

View File

@@ -1,6 +1,5 @@
import 'package:PiliPalaX/common/widgets/http_error.dart';
import 'package:PiliPalaX/http/loading_state.dart';
import 'package:PiliPalaX/pages/video/detail/reply_new/reply_page.dart';
import 'package:PiliPalaX/pages/video/detail/reply_reply/view.dart';
import 'package:easy_debounce/easy_throttle.dart';
import 'package:flutter/material.dart';
@@ -10,7 +9,6 @@ import 'package:PiliPalaX/common/skeleton/video_reply.dart';
import 'package:PiliPalaX/models/common/reply_type.dart';
import 'package:PiliPalaX/utils/feed_back.dart';
import 'package:PiliPalaX/utils/id_utils.dart';
import 'package:get/get_navigation/src/dialog/dialog_route.dart';
import 'controller.dart';
import 'widgets/reply_item.dart';
@@ -39,8 +37,6 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
late VideoReplyController _videoReplyController;
late AnimationController fabAnimationCtr;
late final _savedReplies = {};
bool _isFabVisible = true;
String replyLevel = '1';
late String heroTag;
@@ -204,78 +200,7 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
feedBack();
dynamic oid = _videoReplyController.aid ??
IdUtils.bv2av(Get.parameters['bvid']!);
Navigator.of(context)
.push(
GetDialogRoute(
pageBuilder:
(buildContext, animation, secondaryAnimation) {
return ReplyPage(
oid: oid,
root: 0,
parent: 0,
replyType: ReplyType.video,
savedReply: _savedReplies[oid],
onSaveReply: (reply) {
_savedReplies[oid] = reply;
},
);
},
transitionDuration: const Duration(milliseconds: 500),
transitionBuilder:
(context, animation, secondaryAnimation, child) {
const begin = Offset(0.0, 1.0);
const end = Offset.zero;
const curve = Curves.linear;
var tween = Tween(begin: begin, end: end)
.chain(CurveTween(curve: curve));
return SlideTransition(
position: animation.drive(tween),
child: child,
);
},
),
)
.then(
(value) {
// 完成评论,数据添加
if (value != null && value['data'] != null) {
_savedReplies[oid] = null;
List list =
_videoReplyController.loadingState.value is Success
? (_videoReplyController.loadingState.value
as Success)
.response
: [];
list.insert(0, value['data']);
_videoReplyController.loadingState.value =
LoadingState.success(list);
}
},
);
// 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
// .insert(0, value['data'])
// }
// },
// );
_videoReplyController.onReply(context, oid: oid);
},
tooltip: '发表评论',
child: const Icon(Icons.reply),
@@ -317,70 +242,13 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
replyReply: replyReply,
replyType: ReplyType.video,
onReply: () {
dynamic oid = loadingState.response[index].oid;
dynamic root = loadingState.response[index].rpid;
dynamic parent = loadingState.response[index].rpid;
dynamic key = oid + root + parent;
Navigator.of(context)
.push(
GetDialogRoute(
pageBuilder:
(buildContext, animation, secondaryAnimation) {
return ReplyPage(
oid: oid,
root: root,
parent: parent,
replyType: ReplyType.video,
replyItem: loadingState.response[index],
savedReply: _savedReplies[key],
onSaveReply: (reply) {
_savedReplies[key] = reply;
},
);
},
transitionDuration: const Duration(milliseconds: 500),
transitionBuilder:
(context, animation, secondaryAnimation, child) {
const begin = Offset(0.0, 1.0);
const end = Offset.zero;
const curve = Curves.linear;
var tween = Tween(begin: begin, end: end)
.chain(CurveTween(curve: curve));
return SlideTransition(
position: animation.drive(tween),
child: child,
);
},
),
)
.then((value) {
// 完成评论,数据添加
if (value != null && value['data'] != null) {
_savedReplies[key] = null;
}
});
},
onDelete: (rpid, frpid) {
List list =
(_videoReplyController.loadingState.value as Success)
.response;
list = frpid == null
? list.where((item) => item.rpid != rpid).toList()
: list.map((item) {
if (item.rpid == frpid) {
return item
..replies = item.replies
?.where((reply) => reply.rpid != rpid)
.toList();
} else {
return item;
}
}).toList();
_videoReplyController.loadingState.value =
LoadingState.success(list);
_videoReplyController.onReply(
context,
replyItem: loadingState.response[index],
index: index,
);
},
onDelete: _videoReplyController.onMDelete,
);
}
},

View File

@@ -5,7 +5,6 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:get/get_navigation/src/dialog/dialog_route.dart';
import 'package:hive/hive.dart';
import 'package:PiliPalaX/common/widgets/badge.dart';
import 'package:PiliPalaX/common/widgets/network_img_layer.dart';
@@ -17,7 +16,6 @@ import 'package:PiliPalaX/utils/storage.dart';
import 'package:PiliPalaX/utils/url_utils.dart';
import 'package:PiliPalaX/utils/utils.dart';
import '../../../../../utils/app_scheme.dart';
import '../../reply_new/reply_page.dart';
import 'zan.dart';
Box setting = GStorage.setting;
@@ -26,7 +24,6 @@ class ReplyItem extends StatelessWidget {
const ReplyItem({
super.key,
this.replyItem,
this.addReply,
this.replyLevel,
this.showReplyRow = true,
this.replyReply,
@@ -36,7 +33,6 @@ class ReplyItem extends StatelessWidget {
this.onDelete,
});
final ReplyItemModel? replyItem;
final Function? addReply;
final String? replyLevel;
final bool? showReplyRow;
final Function? replyReply;
@@ -324,68 +320,6 @@ class ReplyItem extends StatelessWidget {
onReply!();
return;
}
Navigator.of(context)
.push(
GetDialogRoute(
pageBuilder:
(buildContext, animation, secondaryAnimation) {
return ReplyPage(
oid: replyItem!.oid,
root: replyItem!.rpid,
parent: replyItem!.rpid,
replyType: replyType,
replyItem: replyItem,
);
},
transitionDuration: const Duration(milliseconds: 500),
transitionBuilder:
(context, animation, secondaryAnimation, child) {
const begin = Offset(0.0, 1.0);
const end = Offset.zero;
const curve = Curves.linear;
var tween = Tween(begin: begin, end: end)
.chain(CurveTween(curve: curve));
return SlideTransition(
position: animation.drive(tween),
child: child,
);
},
),
)
.then((value) => {
// 完成评论,数据添加
if (value != null &&
value['data'] != null &&
addReply != null)
{
addReply?.call(value['data'])
// replyControl.replies.add(value['data']),
}
});
// showModalBottomSheet(
// context: context,
// isScrollControlled: true,
// builder: (builder) {
// return VideoReplyNewDialog(
// oid: replyItem!.oid,
// root: replyItem!.rpid,
// parent: replyItem!.rpid,
// replyType: replyType,
// replyItem: replyItem,
// );
// },
// ).then((value) => {
// // 完成评论,数据添加
// if (value != null &&
// value['data'] != null &&
// addReply != null)
// {
// addReply?.call(value['data'])
// // replyControl.replies.add(value['data']),
// }
// });
},
child: Row(children: [
Icon(Icons.reply,

View File

@@ -47,7 +47,7 @@ class _ReplyPageState extends State<ReplyPage>
late final _controller = ChatBottomPanelContainerController<PanelType>();
late final TextEditingController _replyContentController =
TextEditingController(text: widget.savedReply);
PanelType _currentPanelType = PanelType.none;
// PanelType _currentPanelType = PanelType.none;
bool _readOnly = false;
final _readOnlyStream = StreamController<bool>();
late final _enableSend = StreamController<bool>();
@@ -124,28 +124,28 @@ class _ReplyPageState extends State<ReplyPage>
return const SizedBox.shrink();
}
},
onPanelTypeChange: (panelType, data) {
debugPrint('panelType: $panelType');
switch (panelType) {
case ChatBottomPanelType.none:
_currentPanelType = PanelType.none;
break;
case ChatBottomPanelType.keyboard:
_currentPanelType = PanelType.keyboard;
break;
case ChatBottomPanelType.other:
if (data == null) return;
switch (data) {
case PanelType.emoji:
_currentPanelType = PanelType.emoji;
break;
default:
_currentPanelType = PanelType.none;
break;
}
break;
}
},
// onPanelTypeChange: (panelType, data) {
// debugPrint('panelType: $panelType');
// switch (panelType) {
// case ChatBottomPanelType.none:
// _currentPanelType = PanelType.none;
// break;
// case ChatBottomPanelType.keyboard:
// _currentPanelType = PanelType.keyboard;
// break;
// case ChatBottomPanelType.other:
// if (data == null) return;
// switch (data) {
// case PanelType.emoji:
// _currentPanelType = PanelType.emoji;
// break;
// default:
// _currentPanelType = PanelType.none;
// break;
// }
// break;
// }
// },
panelBgColor: Theme.of(context).colorScheme.surface,
);
}

View File

@@ -114,9 +114,6 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
replyItem: widget.firstFloor,
replyLevel: '2',
showReplyRow: false,
addReply: (replyItem) {
// _videoReplyReplyController.replyList.add(replyItem);
},
replyType: widget.replyType,
replyReply: () {},
needDivider: false,
@@ -185,6 +182,13 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
// 完成评论,数据添加
if (value != null && value['data'] != null) {
_savedReplies[key] = null;
List list = _videoReplyReplyController.loadingState.value is Success
? (_videoReplyReplyController.loadingState.value as Success)
.response
: [];
list.add(value['data']);
_videoReplyReplyController.loadingState.value =
LoadingState.success(list);
}
});
}
@@ -200,9 +204,6 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
replyItem: _videoReplyReplyController.root,
replyLevel: '2',
showReplyRow: false,
addReply: (replyItem) {
// _videoReplyReplyController.replyList.add(replyItem);
},
replyType: widget.replyType,
replyReply: () {},
needDivider: false,
@@ -244,18 +245,18 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
replyItem: loadingState.response[index],
replyLevel: '2',
showReplyRow: false,
addReply: (replyItem) {
// _videoReplyReplyController.replyList.add(replyItem);
},
replyType: widget.replyType,
onReply: () {
_onReply(loadingState.response[index]);
},
onDelete: (rpid, frpid) {
// _videoReplyReplyController.replyList.value =
// _videoReplyReplyController.replyList
// .where((item) => item.rpid != rpid)
// .toList();
List list = (_videoReplyReplyController
.loadingState.value as Success)
.response;
list =
list.where((item) => item.rpid != rpid).toList();
_videoReplyReplyController.loadingState.value =
LoadingState.success(list);
},
);
}