fluttercandies / like_button

Like Button is a flutter library that allows you to create a button with animation effects similar to Twitter's heart when you like something and animation effects to increase like count.
MIT License
469 stars 96 forks source link

Add item index support #83

Open AfroCyberGuy opened 8 months ago

AfroCyberGuy commented 8 months ago

Platforms

dart

Description

Can we add a feature to accept an optional index on the like button it helps when we want to do a request that required to get the item liked i.e in this case with an index. because onTap: Future<bool?> Function(bool)? onTap function is very limited i will be happy to contribute.

Why

Screenshot 2024-02-20 at 10 11 00
 child: RecommendedCard(
                            width: getScreenWidth(context) / 2.5,
                            height: getScreenWidth(context) / 2.5,
                            image: '$imageBaseUrl/${event.image}',
                            tagText: event.category?.name ?? '',
                            titleText: event.title ?? '',
                            dateText: event.date ?? '',
                            onLike: () async {
                              await notifier.like(event.id ?? 0, index);
                            },
                            isFavourite: event.isliked ?? 0,
                           //onLikeButtonTapped does a request and it needs and index button like button only accept this function type[ Future<bool?> Function(bool)? onTap ]
                            onTap: notifier.onLikeButtonTapped,
                          ),
                        );
                      },
                    ),
                //This is my controller with notifier.onLikeButtonTapped method
                 //This is the function accepted by LikeButton , so its limited i can get an object tapped so that i can do a proper request
                      Future<bool> onLikeButtonTapped(bool isLiked) async {
    int likeStatus = 0;

    setLikingStatus(true);
    state = state.copyWith(likeEventResult: const AsyncValue.loading());

    final result = await _recommendedEventsServiceImpl.like(
      LikeRequest(
        eventId: state.eventId,
        userId: int.parse(_preferencesNotifier.getUserID()),
      ),
    );
zmtzawqlp commented 8 months ago

I think you don't need do as that. A custom widget include your item data and LikeButton will work.

AfroCyberGuy commented 8 months ago

I think you don't need do as that. A custom widget include your item data and LikeButton will work.

Oww yes yes thank you for your timely response, I think I have logged this as a feature request and not issue. I have it working already but its just a suggestion to enhance LikeButton.