comments final
This commit is contained in:
parent
293e759499
commit
f6fb9082ce
|
|
@ -26,6 +26,8 @@ class Comments extends StatefulWidget {
|
|||
|
||||
class _CommentsState extends State<Comments> {
|
||||
final _focusNode = FocusNode();
|
||||
double _bottomPadding = 0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
final state = context.read<CommentsState>();
|
||||
|
|
@ -41,6 +43,14 @@ class _CommentsState extends State<Comments> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final bottomViewInset = MediaQuery.of(context).viewInsets.bottom;
|
||||
if (bottomViewInset == 0) {
|
||||
if (_bottomPadding != 0) {
|
||||
FocusScope.of(context).unfocus();
|
||||
_bottomPadding = 0;
|
||||
}
|
||||
}
|
||||
_bottomPadding = bottomViewInset;
|
||||
return Material(
|
||||
child: Stack(
|
||||
children: [
|
||||
|
|
@ -99,7 +109,7 @@ class _MessageBoxState extends State<_MessageBox> {
|
|||
children: [
|
||||
AnimatedVisibility(
|
||||
duration: DesignConfig.lowAnimationDuration,
|
||||
isVisible: state.replyingTo != null,
|
||||
isVisible: state.showReplyBox,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
|
|
@ -127,6 +137,7 @@ class _MessageBoxState extends State<_MessageBox> {
|
|||
onPressed: () {
|
||||
state.commentId = null;
|
||||
state.replyingTo = null;
|
||||
state.showReplyBox = false;
|
||||
state.update();
|
||||
},
|
||||
),
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ class CommentsState extends CoreProvier {
|
|||
String text = '';
|
||||
int? commentId;
|
||||
UserOverview? replyingTo;
|
||||
bool showReplyBox = false;
|
||||
late VoidCallback onCommentAdded;
|
||||
|
||||
final List<CommentData> comments = [];
|
||||
|
|
@ -62,23 +63,22 @@ class CommentsState extends CoreProvier {
|
|||
Future<void> addComment() async {
|
||||
final user = DesignConfig.context.read<UserProvider>().user;
|
||||
if (replyingTo != null) {
|
||||
final comment = comments.firstWhere((comment) => comment.id == commentId);
|
||||
comment.replies.add(
|
||||
Reply(
|
||||
id: 0,
|
||||
text: text,
|
||||
createdAt: DateTime.now().toString(),
|
||||
liked: false,
|
||||
disliked: false,
|
||||
feedback: const FeedbackData(like: 0, dislike: 0),
|
||||
toUser: replyingTo!,
|
||||
user: UserOverview(
|
||||
id: user.id,
|
||||
fullName: user.fullName,
|
||||
photo: user.photo,
|
||||
),
|
||||
),
|
||||
);
|
||||
comments.firstWhere((comment) => comment.id == commentId).replies.add(
|
||||
Reply(
|
||||
id: 0,
|
||||
text: text,
|
||||
createdAt: DateTime.now().toString(),
|
||||
liked: false,
|
||||
disliked: false,
|
||||
feedback: const FeedbackData(like: 0, dislike: 0),
|
||||
toUser: replyingTo!,
|
||||
user: UserOverview(
|
||||
id: user.id,
|
||||
fullName: user.fullName,
|
||||
photo: user.photo,
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
comments.insert(
|
||||
0,
|
||||
|
|
@ -109,22 +109,30 @@ class CommentsState extends CoreProvier {
|
|||
if (replyingTo != null) {
|
||||
body.addAll({'replyUserId': replyingTo!.id});
|
||||
}
|
||||
|
||||
showReplyBox = false;
|
||||
update();
|
||||
body.addAll({'text': text});
|
||||
final service = RequestService(
|
||||
isRadar
|
||||
? RequestHelper.addRadarComment(itemId)
|
||||
: RequestHelper.addNewsComment(itemId),
|
||||
body: body);
|
||||
commentId = null;
|
||||
replyingTo = null;
|
||||
update();
|
||||
|
||||
await service.post();
|
||||
if (service.isSuccess) {
|
||||
if (replyingTo != null) {
|
||||
comments.firstWhere((comment) => comment.id == commentId).id =
|
||||
comments
|
||||
.firstWhere((comment) => comment.id == commentId)
|
||||
.replies
|
||||
.firstWhere((reply) => reply.id == 0)
|
||||
.id = service.result['comment']['id'];
|
||||
} else {
|
||||
comments.firstWhere((comment) => comment.id == 0).id =
|
||||
service.result['comment']['id'];
|
||||
}
|
||||
commentId = null;
|
||||
replyingTo = null;
|
||||
}
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue