comment count bug fixed

This commit is contained in:
MohammadTaha Basiri 2022-01-30 16:23:11 +03:30
parent 5b166b9d97
commit 6da1f5f9f3
4 changed files with 18 additions and 6 deletions

View File

@ -33,7 +33,7 @@ class _CommentsState extends State<Comments> {
final state = context.read<CommentsState>();
state.itemId = widget.pageData['id'];
state.isRadar = widget.pageData['isRadar'];
state.onCommentAdded = widget.pageData['onCommentAdded'];
state.onCommentsChanged = widget.pageData['onCommentsChanged'];
Future.delayed(
Duration.zero,
() => state.getComments(),

View File

@ -8,7 +8,6 @@ import 'package:didvan/providers/core_provider.dart';
import 'package:didvan/providers/user_provider.dart';
import 'package:didvan/services/network/request.dart';
import 'package:didvan/services/network/request_helper.dart';
import 'package:flutter/cupertino.dart';
import 'package:provider/provider.dart';
class CommentsState extends CoreProvier {
@ -16,7 +15,8 @@ class CommentsState extends CoreProvier {
int? commentId;
UserOverview? replyingTo;
bool showReplyBox = false;
late VoidCallback onCommentAdded;
late void Function(int count) onCommentsChanged;
int _count = 0;
final List<CommentData> comments = [];
final Map<int, MapEntry<bool, bool>> _feedbackQueue = {};
@ -36,6 +36,10 @@ class CommentsState extends CoreProvier {
final messages = service.result['comments'];
for (var i = 0; i < messages.length; i++) {
comments.add(CommentData.fromJson(messages[i]));
_count++;
for (var j = 0; j < messages[i]['replies'].length; j++) {
_count++;
}
}
appState = AppState.idle;
return;
@ -99,7 +103,8 @@ class CommentsState extends CoreProvier {
);
}
onCommentAdded();
_count++;
onCommentsChanged(_count);
final body = {};

View File

@ -114,7 +114,8 @@ class RadarOverview extends StatelessWidget {
'isRadar': true,
'title': radar.title,
'id': radar.id,
'onCommentsChanged': onCommentsChanged
'onCommentsChanged': (count) =>
onCommentsChanged(radar.id, count)
},
),
),

View File

@ -46,6 +46,12 @@ class _FloatingNavigationBarState extends State<FloatingNavigationBar> {
bool _isScrolled = false;
int _comments = 0;
@override
void didUpdateWidget(covariant FloatingNavigationBar oldWidget) {
_comments = widget.comments;
super.didUpdateWidget(oldWidget);
}
@override
void initState() {
_isScrolled = false;
@ -106,7 +112,7 @@ class _FloatingNavigationBarState extends State<FloatingNavigationBar> {
bigGestureSize: true,
),
SizedBox(
width: 48,
width: 60,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [