comments bug fixed
This commit is contained in:
parent
9884ae72f6
commit
f7da888559
|
|
@ -25,6 +25,7 @@ class Comments extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _CommentsState extends State<Comments> {
|
class _CommentsState extends State<Comments> {
|
||||||
|
final _focusNode = FocusNode();
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
final state = context.read<CommentsState>();
|
final state = context.read<CommentsState>();
|
||||||
|
|
@ -61,6 +62,7 @@ class _CommentsState extends State<Comments> {
|
||||||
childCount: state.comments.length,
|
childCount: state.comments.length,
|
||||||
placeholder: const _CommentPlaceholder(),
|
placeholder: const _CommentPlaceholder(),
|
||||||
builder: (context, state, index) => Comment(
|
builder: (context, state, index) => Comment(
|
||||||
|
focusNode: _focusNode,
|
||||||
comment: state.comments[index],
|
comment: state.comments[index],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
@ -68,10 +70,10 @@ class _CommentsState extends State<Comments> {
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
Positioned(
|
Positioned(
|
||||||
bottom: MediaQuery.of(context).viewInsets.bottom,
|
|
||||||
left: 0,
|
left: 0,
|
||||||
right: 0,
|
right: 0,
|
||||||
child: const _MessageBox(),
|
bottom: MediaQuery.of(context).viewInsets.bottom,
|
||||||
|
child: _MessageBox(focusNode: _focusNode),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
@ -80,7 +82,8 @@ class _CommentsState extends State<Comments> {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _MessageBox extends StatefulWidget {
|
class _MessageBox extends StatefulWidget {
|
||||||
const _MessageBox({Key? key}) : super(key: key);
|
final FocusNode focusNode;
|
||||||
|
const _MessageBox({Key? key, required this.focusNode}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<_MessageBox> createState() => _MessageBoxState();
|
State<_MessageBox> createState() => _MessageBoxState();
|
||||||
|
|
@ -150,7 +153,9 @@ class _MessageBoxState extends State<_MessageBox> {
|
||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: TextField(
|
child: TextField(
|
||||||
|
focusNode: widget.focusNode,
|
||||||
controller: _controller,
|
controller: _controller,
|
||||||
|
keyboardType: TextInputType.multiline,
|
||||||
textInputAction: TextInputAction.send,
|
textInputAction: TextInputAction.send,
|
||||||
style: Theme.of(context).textTheme.bodyText2,
|
style: Theme.of(context).textTheme.bodyText2,
|
||||||
onEditingComplete: () {},
|
onEditingComplete: () {},
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
import 'dart:math';
|
|
||||||
|
|
||||||
import 'package:didvan/config/design_config.dart';
|
import 'package:didvan/config/design_config.dart';
|
||||||
import 'package:didvan/models/comment/comment.dart';
|
import 'package:didvan/models/comment/comment.dart';
|
||||||
import 'package:didvan/models/comment/feedback.dart';
|
import 'package:didvan/models/comment/feedback.dart';
|
||||||
|
|
@ -64,10 +62,10 @@ class CommentsState extends CoreProvier {
|
||||||
Future<void> addComment() async {
|
Future<void> addComment() async {
|
||||||
final user = DesignConfig.context.read<UserProvider>().user;
|
final user = DesignConfig.context.read<UserProvider>().user;
|
||||||
if (replyingTo != null) {
|
if (replyingTo != null) {
|
||||||
final coment = comments.firstWhere((comment) => comment.id == commentId);
|
final comment = comments.firstWhere((comment) => comment.id == commentId);
|
||||||
coment.replies.add(
|
comment.replies.add(
|
||||||
Reply(
|
Reply(
|
||||||
id: Random().nextInt(1000),
|
id: 0,
|
||||||
text: text,
|
text: text,
|
||||||
createdAt: DateTime.now().toString(),
|
createdAt: DateTime.now().toString(),
|
||||||
liked: false,
|
liked: false,
|
||||||
|
|
@ -85,7 +83,7 @@ class CommentsState extends CoreProvier {
|
||||||
comments.insert(
|
comments.insert(
|
||||||
0,
|
0,
|
||||||
CommentData(
|
CommentData(
|
||||||
id: Random().nextInt(1000),
|
id: 0,
|
||||||
text: text,
|
text: text,
|
||||||
createdAt: DateTime.now().toString(),
|
createdAt: DateTime.now().toString(),
|
||||||
liked: false,
|
liked: false,
|
||||||
|
|
@ -121,6 +119,12 @@ class CommentsState extends CoreProvier {
|
||||||
replyingTo = null;
|
replyingTo = null;
|
||||||
update();
|
update();
|
||||||
await service.post();
|
await service.post();
|
||||||
|
if (service.isSuccess) {
|
||||||
|
if (replyingTo != null) {
|
||||||
|
comments.firstWhere((comment) => comment.id == commentId).id =
|
||||||
|
service.result['comment']['id'];
|
||||||
|
}
|
||||||
|
}
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,9 +13,11 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
class Comment extends StatefulWidget {
|
class Comment extends StatefulWidget {
|
||||||
|
final FocusNode focusNode;
|
||||||
final CommentData comment;
|
final CommentData comment;
|
||||||
const Comment({
|
const Comment({
|
||||||
Key? key,
|
Key? key,
|
||||||
|
required this.focusNode,
|
||||||
required this.comment,
|
required this.comment,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
|
|
@ -113,6 +115,7 @@ class CommentState extends State<Comment> {
|
||||||
state.commentId = _comment.id;
|
state.commentId = _comment.id;
|
||||||
state.replyingTo = comment.user;
|
state.replyingTo = comment.user;
|
||||||
state.update();
|
state.update();
|
||||||
|
widget.focusNode.requestFocus();
|
||||||
},
|
},
|
||||||
child: DidvanText(
|
child: DidvanText(
|
||||||
'پاسخ',
|
'پاسخ',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue