mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-22 12:59:21 +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/groups_list.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/comment.dart';
|
||||||
import 'package:comunic/models/like_element.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';
|
||||||
import 'package:comunic/ui/tiles/comment_tile.dart';
|
import 'package:comunic/ui/tiles/comment_tile.dart';
|
||||||
import 'package:comunic/ui/widgets/account_image_widget.dart';
|
import 'package:comunic/ui/widgets/account_image_widget.dart';
|
||||||
import 'package:comunic/ui/widgets/countdown_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/network_image_widget.dart';
|
||||||
import 'package:comunic/ui/widgets/survey_widget.dart';
|
import 'package:comunic/ui/widgets/survey_widget.dart';
|
||||||
import 'package:comunic/utils/date_utils.dart';
|
import 'package:comunic/utils/date_utils.dart';
|
||||||
@ -71,7 +71,6 @@ class PostTile extends StatefulWidget {
|
|||||||
class _PostTileState extends State<PostTile> {
|
class _PostTileState extends State<PostTile> {
|
||||||
// Helpers
|
// Helpers
|
||||||
final _postsHelper = PostsHelper();
|
final _postsHelper = PostsHelper();
|
||||||
final _likesHelper = LikesHelper();
|
|
||||||
final _commentsHelper = CommentsHelper();
|
final _commentsHelper = CommentsHelper();
|
||||||
|
|
||||||
// Class members
|
// Class members
|
||||||
@ -212,28 +211,15 @@ class _PostTileState extends State<PostTile> {
|
|||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
// Like button
|
// Like button
|
||||||
Center(
|
Center(
|
||||||
child: InkWell(
|
child: LikeWidget(
|
||||||
onTap: () => _updatePostLike(),
|
likeType: LikesType.POST,
|
||||||
child: Row(
|
likeID: widget.post.id,
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
likesCount: widget.post.likes,
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
isLiking: widget.post.userLike,
|
||||||
children: <Widget>[
|
onUpdatedLikings: (num, userLike) {
|
||||||
Padding(
|
widget.post.likes = num;
|
||||||
padding: const EdgeInsets.only(left: 8.0, right: 8.0),
|
widget.post.userLike = userLike;
|
||||||
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()}))
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -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
|
/// Update comment content
|
||||||
Future<void> _updateCommentContent(Comment comment) async {
|
Future<void> _updateCommentContent(Comment comment) async {
|
||||||
final newContent = await askUserString(
|
final newContent = await askUserString(
|
||||||
|
@ -55,11 +55,8 @@ class _LikeWidgetState extends SafeState<LikeWidget> {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.only(top: 4.0, bottom: 4.0),
|
padding: const EdgeInsets.only(top: 4.0, bottom: 4.0),
|
||||||
child: Align(
|
child: IntrinsicWidth(
|
||||||
alignment: AlignmentDirectional.topStart,
|
child: InkWell(
|
||||||
child: Column(
|
|
||||||
children: <Widget>[
|
|
||||||
InkWell(
|
|
||||||
onTap: () => _toggleLike(),
|
onTap: () => _toggleLike(),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
@ -75,8 +72,6 @@ class _LikeWidgetState extends SafeState<LikeWidget> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user