mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-22 12:59:21 +00:00
Can update like status
This commit is contained in:
parent
2e4d3119f8
commit
9290617cd5
@ -13,8 +13,8 @@ class Comment {
|
|||||||
final int timeSent;
|
final int timeSent;
|
||||||
final String content;
|
final String content;
|
||||||
final String imageURL;
|
final String imageURL;
|
||||||
final int likes;
|
int likes;
|
||||||
final bool userLike;
|
bool userLike;
|
||||||
|
|
||||||
Comment({
|
Comment({
|
||||||
@required this.id,
|
@required this.id,
|
||||||
|
@ -2,6 +2,7 @@ import 'package:comunic/models/comment.dart';
|
|||||||
import 'package:comunic/models/user.dart';
|
import 'package:comunic/models/user.dart';
|
||||||
import 'package:comunic/ui/widgets/account_image_widget.dart';
|
import 'package:comunic/ui/widgets/account_image_widget.dart';
|
||||||
import 'package:comunic/ui/widgets/network_image_widget.dart';
|
import 'package:comunic/ui/widgets/network_image_widget.dart';
|
||||||
|
import 'package:comunic/utils/intl_utils.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
/// Single comment tile
|
/// Single comment tile
|
||||||
@ -11,10 +12,16 @@ import 'package:flutter/material.dart';
|
|||||||
class CommentTile extends StatelessWidget {
|
class CommentTile extends StatelessWidget {
|
||||||
final Comment comment;
|
final Comment comment;
|
||||||
final User user;
|
final User user;
|
||||||
|
final void Function(Comment) onUpdateLike;
|
||||||
|
|
||||||
const CommentTile({Key key, this.comment, this.user})
|
const CommentTile({
|
||||||
: assert(comment != null),
|
Key key,
|
||||||
|
@required this.comment,
|
||||||
|
@required this.user,
|
||||||
|
@required this.onUpdateLike,
|
||||||
|
}) : assert(comment != null),
|
||||||
assert(user != null),
|
assert(user != null),
|
||||||
|
assert(onUpdateLike != null),
|
||||||
super(key: key);
|
super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -23,7 +30,9 @@ class CommentTile extends StatelessWidget {
|
|||||||
leading: AccountImageWidget(
|
leading: AccountImageWidget(
|
||||||
user: user,
|
user: user,
|
||||||
),
|
),
|
||||||
title: Text(user.displayName,),
|
title: Text(
|
||||||
|
user.displayName,
|
||||||
|
),
|
||||||
subtitle: _buildCommentContent(),
|
subtitle: _buildCommentContent(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -39,15 +48,55 @@ class CommentTile extends StatelessWidget {
|
|||||||
url: comment.imageURL,
|
url: comment.imageURL,
|
||||||
allowFullScreen: true,
|
allowFullScreen: true,
|
||||||
height: 100.0,
|
height: 100.0,
|
||||||
|
width: null,
|
||||||
)
|
)
|
||||||
: null,
|
: null,
|
||||||
),
|
),
|
||||||
|
|
||||||
// Comment text
|
// Comment text
|
||||||
Container(
|
Container(
|
||||||
child: comment.hasContent ? Text(comment.content,) : null,
|
child: comment.hasContent
|
||||||
|
? Text(
|
||||||
|
comment.content,
|
||||||
|
)
|
||||||
|
: null,
|
||||||
),
|
),
|
||||||
|
|
||||||
|
// Comment likes
|
||||||
|
_buildLikeButton(),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String get _likeString {
|
||||||
|
if (comment.likes == 0) return tr("Like");
|
||||||
|
if (comment.likes == 1)
|
||||||
|
return tr("1 Like");
|
||||||
|
else
|
||||||
|
return tr("%num% likes", args: {"num": comment.likes.toString()});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Build like button associated to this post
|
||||||
|
Widget _buildLikeButton() {
|
||||||
|
return Align(
|
||||||
|
alignment: AlignmentDirectional.topStart,
|
||||||
|
child: FlatButton(
|
||||||
|
padding: EdgeInsets.only(left: 0.0),
|
||||||
|
onPressed: () => onUpdateLike(comment),
|
||||||
|
child: Row(
|
||||||
|
children: <Widget>[
|
||||||
|
Icon(
|
||||||
|
Icons.thumb_up,
|
||||||
|
color: comment.userLike ? Colors.blue : null,
|
||||||
|
size: 15.0,
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
width: 8.0,
|
||||||
|
),
|
||||||
|
Text(_likeString),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import 'package:comunic/enums/post_kind.dart';
|
|||||||
import 'package:comunic/helpers/comments_helper.dart';
|
import 'package:comunic/helpers/comments_helper.dart';
|
||||||
import 'package:comunic/helpers/likes_helper.dart';
|
import 'package:comunic/helpers/likes_helper.dart';
|
||||||
import 'package:comunic/lists/users_list.dart';
|
import 'package:comunic/lists/users_list.dart';
|
||||||
|
import 'package:comunic/models/comment.dart';
|
||||||
import 'package:comunic/models/new_comment.dart';
|
import 'package:comunic/models/new_comment.dart';
|
||||||
import 'package:comunic/models/post.dart';
|
import 'package:comunic/models/post.dart';
|
||||||
import 'package:comunic/models/user.dart';
|
import 'package:comunic/models/user.dart';
|
||||||
@ -192,6 +193,7 @@ class _PostTileState extends State<PostTile> {
|
|||||||
(num) => CommentTile(
|
(num) => CommentTile(
|
||||||
comment: widget.post.comments[num],
|
comment: widget.post.comments[num],
|
||||||
user: widget.usersInfo.getUser(widget.post.comments[num].userID),
|
user: widget.usersInfo.getUser(widget.post.comments[num].userID),
|
||||||
|
onUpdateLike: _updateCommentLike,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -351,4 +353,20 @@ class _PostTileState extends State<PostTile> {
|
|||||||
widget.post.userLikes ? widget.post.likes++ : widget.post.likes--;
|
widget.post.userLikes ? widget.post.likes++ : widget.post.likes--;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Invert comment like status
|
||||||
|
Future<void> _updateCommentLike(Comment comment) async {
|
||||||
|
// Update liking status
|
||||||
|
_likesHelper.setLiking(
|
||||||
|
type: LikesType.COMMENT,
|
||||||
|
like: !comment.userLike,
|
||||||
|
id: comment.id,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Save new like status
|
||||||
|
setState(() {
|
||||||
|
comment.userLike = !comment.userLike;
|
||||||
|
comment.userLike ? comment.likes++ : comment.likes--;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user