mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-12-26 12:58:51 +00:00
Use Like widget on Post element
This commit is contained in:
parent
5f70669a84
commit
2d26395d73
@ -9,13 +9,13 @@ import 'package:comunic/helpers/posts_helper.dart';
|
||||
import 'package:comunic/lists/groups_list.dart';
|
||||
import 'package:comunic/lists/users_list.dart';
|
||||
import 'package:comunic/models/comment.dart';
|
||||
import 'package:comunic/models/like_element.dart';
|
||||
import 'package:comunic/models/new_comment.dart';
|
||||
import 'package:comunic/models/post.dart';
|
||||
import 'package:comunic/models/user.dart';
|
||||
import 'package:comunic/ui/tiles/comment_tile.dart';
|
||||
import 'package:comunic/ui/widgets/account_image_widget.dart';
|
||||
import 'package:comunic/ui/widgets/countdown_widget.dart';
|
||||
import 'package:comunic/ui/widgets/like_widget.dart';
|
||||
import 'package:comunic/ui/widgets/network_image_widget.dart';
|
||||
import 'package:comunic/ui/widgets/survey_widget.dart';
|
||||
import 'package:comunic/utils/date_utils.dart';
|
||||
@ -71,7 +71,6 @@ class PostTile extends StatefulWidget {
|
||||
class _PostTileState extends State<PostTile> {
|
||||
// Helpers
|
||||
final _postsHelper = PostsHelper();
|
||||
final _likesHelper = LikesHelper();
|
||||
final _commentsHelper = CommentsHelper();
|
||||
|
||||
// Class members
|
||||
@ -212,28 +211,15 @@ class _PostTileState extends State<PostTile> {
|
||||
children: <Widget>[
|
||||
// Like button
|
||||
Center(
|
||||
child: InkWell(
|
||||
onTap: () => _updatePostLike(),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0, right: 8.0),
|
||||
child: Icon(
|
||||
Icons.thumb_up,
|
||||
color: widget.post.userLike ? Colors.blue : null,
|
||||
),
|
||||
),
|
||||
Text(widget.post.likes < 2
|
||||
? tr("%num% like",
|
||||
args: {"num": widget.post.likes.toString()})
|
||||
: tr("%num% likes",
|
||||
args: {"num": widget.post.likes.toString()}))
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
child: LikeWidget(
|
||||
likeType: LikesType.POST,
|
||||
likeID: widget.post.id,
|
||||
likesCount: widget.post.likes,
|
||||
isLiking: widget.post.userLike,
|
||||
onUpdatedLikings: (num, userLike) {
|
||||
widget.post.likes = num;
|
||||
widget.post.userLike = userLike;
|
||||
})),
|
||||
],
|
||||
),
|
||||
);
|
||||
@ -519,27 +505,6 @@ class _PostTileState extends State<PostTile> {
|
||||
});
|
||||
}
|
||||
|
||||
/// Update like status
|
||||
Future<void> _updatePostLike() async {
|
||||
_updateElementLike(LikesType.POST, widget.post);
|
||||
}
|
||||
|
||||
/// Invert element like status
|
||||
Future<void> _updateElementLike(LikesType type, LikeElement element) async {
|
||||
// Update liking status
|
||||
_likesHelper.setLiking(
|
||||
type: type,
|
||||
like: !element.userLike,
|
||||
id: element.id,
|
||||
);
|
||||
|
||||
// Save new like status
|
||||
setState(() {
|
||||
element.userLike = !element.userLike;
|
||||
element.userLike ? element.likes++ : element.likes--;
|
||||
});
|
||||
}
|
||||
|
||||
/// Update comment content
|
||||
Future<void> _updateCommentContent(Comment comment) async {
|
||||
final newContent = await askUserString(
|
||||
|
@ -55,27 +55,22 @@ class _LikeWidgetState extends SafeState<LikeWidget> {
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: 4.0, bottom: 4.0),
|
||||
child: Align(
|
||||
alignment: AlignmentDirectional.topStart,
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
InkWell(
|
||||
onTap: () => _toggleLike(),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Icon(
|
||||
Icons.thumb_up,
|
||||
color: widget.isLiking ? Colors.blue : null,
|
||||
size: 15.0,
|
||||
),
|
||||
SizedBox(
|
||||
width: 8.0,
|
||||
),
|
||||
Text(_likeString),
|
||||
],
|
||||
child: IntrinsicWidth(
|
||||
child: InkWell(
|
||||
onTap: () => _toggleLike(),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Icon(
|
||||
Icons.thumb_up,
|
||||
color: widget.isLiking ? Colors.blue : null,
|
||||
size: 15.0,
|
||||
),
|
||||
),
|
||||
],
|
||||
SizedBox(
|
||||
width: 8.0,
|
||||
),
|
||||
Text(_likeString),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user