mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-04 12:14:11 +00:00 
			
		
		
		
	Use Like widget on Post element
This commit is contained in:
		@@ -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,11 +55,8 @@ 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(
 | 
			
		||||
      child: IntrinsicWidth(
 | 
			
		||||
        child: InkWell(
 | 
			
		||||
          onTap: () => _toggleLike(),
 | 
			
		||||
          child: Row(
 | 
			
		||||
            children: <Widget>[
 | 
			
		||||
@@ -75,8 +72,6 @@ class _LikeWidgetState extends SafeState<LikeWidget> {
 | 
			
		||||
            ],
 | 
			
		||||
          ),
 | 
			
		||||
        ),
 | 
			
		||||
          ],
 | 
			
		||||
        ),
 | 
			
		||||
      ),
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user