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.

Overview

like_button

pub package GitHub stars GitHub forks GitHub license GitHub issues flutter-candies

Language: English | 中文简体

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.

Reference codes from jd-alexander and 吉原拉面 ,thank them for open source code.

Web Demo for LikeButton

How to use it.

the default effects is Icons.favorite

  LikeButton(),

and you can also define custom effects.

  LikeButton(
          size: buttonSize,
          circleColor:
              CircleColor(start: Color(0xff00ddff), end: Color(0xff0099cc)),
          bubblesColor: BubblesColor(
            dotPrimaryColor: Color(0xff33b5e5),
            dotSecondaryColor: Color(0xff0099cc),
          ),
          likeBuilder: (bool isLiked) {
            return Icon(
              Icons.home,
              color: isLiked ? Colors.deepPurpleAccent : Colors.grey,
              size: buttonSize,
            );
          },
          likeCount: 665,
          countBuilder: (int count, bool isLiked, String text) {
            var color = isLiked ? Colors.deepPurpleAccent : Colors.grey;
            Widget result;
            if (count == 0) {
              result = Text(
                "love",
                style: TextStyle(color: color),
              );
            } else
              result = Text(
                text,
                style: TextStyle(color: color),
              );
            return result;
          },
        ),

The time to send your request

    LikeButton(
      onTap: onLikeButtonTapped,
    ),
  Future<bool> onLikeButtonTapped(bool isLiked) async{
    /// send your request here
    // final bool success= await sendRequest();

    /// if failed, you can do nothing
    // return success? !isLiked:isLiked;

    return !isLiked;
  }

parameters

parameter description default
size size of like widget 30.0
animationDuration animation duration to change isLiked state const Duration(milliseconds: 1000)
bubblesSize total size of bubbles size * 2.0
bubblesColor colors of bubbles const BubblesColor(dotPrimaryColor: const Color(0xFFFFC107),dotSecondaryColor: const Color(0xFFFF9800),dotThirdColor: const Color(0xFFFF5722),dotLastColor: const Color(0xFFF44336),)
circleSize final size of circle size * 0.8
circleColor colors of circle const CircleColor(start: const Color(0xFFFF5722), end: const Color(0xFFFFC107)
onTap tap call back of like button,you can handle your request in this call back
isLiked whether it is liked(if it's null, always show like animation and increase like count) false
likeCount if null, will not show) null
mainAxisAlignment MainAxisAlignment for like button MainAxisAlignment.center
likeBuilder builder to create like widget null
countBuilder builder to create like count widget null
likeCountAnimationDuration animation duration to change like count const Duration(milliseconds: 500)
likeCountAnimationType animation type to change like count(none,part,all) LikeCountAnimationType.part
likeCountPadding padding for like count widget const EdgeInsets.only(left: 3.0)
countPostion top,right,bottom,left of like button widget CountPostion.right
countDecoration decoration of like count widget null
Comments
  • strange behaviour with like count widget

    strange behaviour with like count widget

    I noticed this issue

    if like count is greater than 10 ex, 11, 12 etc...

    two text widgets are shown there are no errors shown nothing don't know what going wrong

    if like count is less than 10 it works fine

    you can refer the below image

    when setState() is called it gets back to normal but if someone interacts with It it once again reappears

    WhatsApp Image 2019-10-09 at 4 18 23 PM

    and support for changing background colour is also required as you can see now background is light grey

    please provide the solution as soon as possible as I am using this library in live app and users are facing this issue

    opened by VickySalunkhe 18
  • problem with OnTap

    problem with OnTap

    I tried your documentation but when I register OnTap I loose animation effect. this is my code:

    LikeButton(
                                size: 30.0,
                                circleColor: CircleColor(
                                  start: Color(0xffE9C349),
                                  end: Colors.red,
                                ),
                                onTap: (isLiked) async {
                                  await gen.addMusicsToFavorite();
                                  final Completer<bool> completer =
                                      new Completer<bool>();
                                  Timer(
                                    const Duration(milliseconds: 200),
                                    () {
                                      completer.complete(gen.music['is_favorite']);
                                      return completer.future;
                                    },
                                  );
                                },
                                bubblesColor: BubblesColor(
                                  dotPrimaryColor: Colors.red,
                                  dotSecondaryColor: Color(0xffE9C349),
                                ),
                                isLiked: gen.music['is_favorite'],
                                likeBuilder: (bool isLiked) {
                                  return isLiked
                                      ? Icon(
                                          Icons.favorite,
                                          color: Color(0xffE9C349),
                                          size: 30.0,
                                        )
                                      : Icon(
                                          Icons.favorite_border,
                                          color: Colors.white,
                                        );
                                },
                              ),
    

    in my provider class I execute addMusicsToFavorite and then the result will be gen.music['is_favorite'],

    opened by mohammadne 11
  • Like Status resetting when scrolling away

    Like Status resetting when scrolling away

    Similar to #27, but the solution does not work for me.

    I have a like button, inside of a List Tile. when i like it, then scroll it out of view, and back again, the likeBuilder is triggered, but the isLiked boolean of it is false, even though i previously returned true from an onTap call.

    If i use this code, press the like button, the animation plays as expected, but if i scroll down, _currentlyAnsweredNotification.liked stays true, but the Like Button is rebuild as non-liked and can be pressed again (the isLike property of the like builder is also false)

    ListTile(
              title: Text(notificationContent),
              subtitle: Column(
                children: <Widget>[
                  Text(flairText),
                  Container(height: 20, color: null, child: Row()),
                  Container(
                      child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      Text('Helpful? '),
                      LikeButton(
                        size: 70,
                        circleColor: CircleColor(
                            start: Color(0xff00ddff), end: Color(0xff0099cc)),
                        bubblesColor: BubblesColor(
                          dotPrimaryColor: Color(0xff33b5e5),
                          dotSecondaryColor: Color(0xff0099cc),
                        ),
                        isLiked: _currentlyAnsweredNotification.liked,
                        likeBuilder: (bool isLiked) { return Icon(
                             log("likeBuilder is like $isLiked");
                            (isLiked
                                ? Icons.thumb_up
                                : Icons.thumb_up_off_alt),
                            color: Colors.black,
                          );
                        },
                        onTap: (isLiked) async {
                            _currentlyAnsweredNotification.liked =
                                !isLiked; 
                          return  _currentlyAnsweredNotification.liked;
                        },
                      ),
                    ],
                  ))
                ],
              ),
            )
    
    
    StackOverFlow 
    opened by supidupicoder 8
  • Animation is not shown while using onTap Feature

    Animation is not shown while using onTap Feature

    I have wrapped this Like Button with my stateless Widget named Love Button The animation of this like button is working until I use onTap feature after onTap callback added to the widget the animation stops , only color is changed
    Here's my Code

    `class LoveButton extends StatelessWidget { @required final IconData icon; @required final IconData likedIcon; @required final Color startColor; @required final Color endColor; @required final Color dotPrimaryColor; @required final Color dotSecondaryColor; @required final Color likeColor; @required final int likeCount; @required final bool isLiked; @required final LikeButtonTapCallback onTap;

    const LoveButton( {Key key, this.icon, this.dotSecondaryColor, this.dotPrimaryColor, this.endColor, this.startColor, this.likeColor, this.likedIcon, this.likeCount, this.isLiked, this.onTap}) : super(key: key); @override Widget build(BuildContext context) { return LikeButton( size: 24.0, isLiked: isLiked, circleColor: CircleColor(start: startColor, end: endColor), bubblesColor: BubblesColor( dotPrimaryColor: dotPrimaryColor, dotSecondaryColor: dotSecondaryColor, ), onTap: onTap, likeBuilder: (bool isLiked) { return !isLiked ? Icon( icon, color: Colors.grey, size: 24.0, ) : Icon( likedIcon, color: likeColor, size: 24.0, ); }, countPostion: CountPostion.left, likeCountPadding: EdgeInsets.only(right: 3), countDecoration: (Widget count, int likeCount) { var _formattedNumber = NumberFormat.compact().format( likeCount, ); if (likeCount == 0) { count = Text( "", ); } else count = Text( " ${_formattedNumber.toLowerCase()}", style: textTheme.caption.copyWith(color: colorScheme.secondary), ); return count; }, likeCount: likeCount, ); } }`

    Hers My implementation of LovedButton LoveButton( onTap: (bool isLiked) async { print(isLiked); if (!isLiked) { await firestoreService.addLikes( postId: post.postId, currentUserId: sanjuUser.id, ownerId: post.ownerId); await firestoreService.addLikeToActivity( ownerId: post.ownerId, postId: post.postId, currentUserId: sanjuUser.id, mediaUrl: post.mediaUrl, timestamp: new DateTime.now().millisecondsSinceEpoch, displayType: post.type); return isLiked; } else { await firestoreService.deleteLikes( postId: post.postId, currentUserId: sanjuUser.id, ownerId: post.ownerId); await firestoreService.removeLikeFromActivity( ownerId: post.ownerId, postId: post.postId, currentUserId: sanjuUser.id); return !isLiked; } }, isLiked: _isLiked, icon: FeatherIcons.heart, likeCount: 100, likeColor: colorScheme.primary, likedIcon: Icons.favorite, endColor: colorScheme.primary, startColor: colorScheme.primaryVariant, dotPrimaryColor: colorScheme.primaryVariant, dotSecondaryColor: colorScheme.secondaryVariant, ), Please help What should I do to get that animation and background work done.

    opened by rishabhshukla7 8
  • Like ontap issue

    Like ontap issue

    Hi,

    I would like to be able in the tap event to set the liked state and change the state of the button and then call my API.

    It's to avoid lag time of API call.

    onTap: (statusLiked) async { // set Likebutton liked = statusLiked how to do it? return await callApi!(taped); },

    How can I do it?

    opened by dalton5 7
  • animation stopped

    animation stopped

    When i used async function inside onbutton tapped ,animation is stopped,i tried many times or it will show initial color of button not updating liked color

    StackOverFlow 
    opened by venky9885 7
  • No way to pass record_id to onLikeButtonTapped

    No way to pass record_id to onLikeButtonTapped

    Hi,

    I'm using following code mentioned here https://pub.dev/packages/like_button#how-to-use-it , it passes isLiked value on onTap:onLikeButtonTapped, But issue is how we can pass record_id we are getting from server to this method? As we need to pass back record_id to server when we Tap on this LikeButton.

    Any thoughtS?

    Thanks :)

    opened by AteqEjaz 6
  • Strange async behaviour

    Strange async behaviour

    Hey guys great library but a question when i run the like count and isLiked from a stream and have the onTap trigger a change in the value on a remote server it breaks the animation any suggestion

    ontap: Future flameToggle(bool isLiked) async { await context .read() .myDB .setContentLiked(!isLiked)); return !isLiked; }

    also i have the isLiked being set initially if liked or not from the stream

    isLiked: mycontentModelStream.myContent.isLiked)

    the values update but no animations

    opened by zaidkazi 5
  • Button shows no reaction when invoking onTap via GlobalKey

    Button shows no reaction when invoking onTap via GlobalKey

    I create a GlobalKey for each LikeButton and want to invoke it from another onTap event.

    Thats the onTap event of the button: key: _e.get('room')['globalKey'], onTap: (liked) async{ print('${liked}'); return !liked; },

    But when i invoke it like this, nothing happens final LikeButton lk = _e.get('room')['globalKey'].currentWidget; lk.onTap(false);

    So i see the print-output, but the button doesnt react at all.

    Any idea, what i am doing wrong?

    Thanks for your help

    opened by tanzmeier 5
  • No option provided to send multiple or extra params in callback

    No option provided to send multiple or extra params in callback

    typedef LikeWidgetBuilder = Widget Function(bool isLiked);

    As per the above the code/line LikeWidgetBuilder is not allowing user to send multiple or extra params. Which is an issue

    opened by jakthegr8 5
  • No

    No "Unlike" behaviour

    Is there any way I can use it as a simple button, instead of a toggle button? I would like the user to be able to click the button for likes, but don't want them to click again to Unlikes, so the button will behave as a normal button, always showing animation for likes and incementing like counts, never decreasing like counts.

    enhancement 
    opened by ch3ckmat3 5
  • Use InkResponse instead of GestureDetector

    Use InkResponse instead of GestureDetector

    I believe, LikeButton should use InkResponse instead of GestureDetector inside the code here. The InkResponse can then also use the appropriate HoverColor and HighlightColor.

    This can also be seen in Twitters design: 8lvvMWYiXm

    This would also provide changing the Cursor automatically on hover, on Desktop / Web.

    To perfectly recreate the Twitter behaviour, a custom InkHighlight and a MouseRegion might be needed, instead of InkResponse.

    Furthermore, I believe that if onTap is null, the LikeButton should be disabled. the Icon and Text inside of the LikeButton should then change its Color to a disabled state. It would be nice if LikeButton had its own ButtonStyle, with appropriate MaterialStateProperty like other buttons.

    This would help to make LikeButton feel more like official Flutter widgets.

    opened by clragon 0
Owner
FlutterCandies
Custom Flutter candies (packages) for you to build your Flutter app easily. Enjoy it!
FlutterCandies
3d Drawer Animated && Made with algeria heart

Cool 3D Drawer Animated With flutter part 1 ?? ?? Getting Started # You need to import this in our file import 'dart:math'; import 'package:flutter/m

Hmida 8 Sep 10, 2022
Progress State Button - A customizable progress button for Flutter

Progress State Button - A customizable progress button for Flutter

Selim 108 Dec 12, 2022
A flutter package which contains a collection of some cool and beautiful effects; support android and ios

flutter effects A flutter package which contains a collection of some cool and beautiful effects; support android and ios . Screenshot type support ch

大海豚 462 Jan 3, 2023
Flutter animation tutorials, such common animation, flare animation.

❤️ Star ❤️ the repo to support the project or ?? Follow Me.Thanks! Facebook Page Facebook Group QQ Group Developer Flutter Open Flutter Open 963828159

Flutter开源社区 123 Sep 3, 2022
Flutter animation tutorials, such common animation, flare animation.

❤️ Star ❤️ the repo to support the project or ?? Follow Me.Thanks! Facebook Page Facebook Group QQ Group Developer Flutter Open Flutter Open 963828159

Flutter开源社区 123 Sep 3, 2022
A sample for having PageView transformation effects in Flutter.

What is it? The end result looks a little something like this: Sample project for creating nice looking PageView parallax effects in Flutter. Read the

Iiro Krankka 811 Dec 22, 2022
Render After Effects animations natively on Flutter. This package is a pure Dart implementation of a Lottie player.

Lottie for Flutter Lottie is a mobile library for Android and iOS that parses Adobe After Effects animations exported as json with Bodymovin and rende

Xavier H. 894 Jan 2, 2023
Render After Effects animations natively on Flutter

Draw Lottie files on a Flutter Widget

Bouziani Mohammed 2 Mar 10, 2022
This flutter package contains a widget called DecodingTextEffect which is having some cool Decode Effects for texts.

This flutter package contains a widget called DecodingTextEffect which is having some cool Decode Effects for texts. Installing 1. Depend on it Add th

Aadarsh Patel 13 Nov 25, 2020
Add particle effects to anything.

Showcase Features Highly customizable (Don't like my particle effects? Make your own with little effort!) Very easy to use A lot of premade particles

Norbert Kozsir 271 Oct 2, 2022
Loading widget based on a Flare animation, allow you to create beautiful custom loading widgets or dialogs

flare_loading Loading widget based on a Flare animation, allow you to create custom loading widgets or dialogs If you're using Rive instead of Flare p

Jimmy Aumard 25 Apr 16, 2021
Create powerful animations in Flutter and use the hero animation for complex animations

Hero Animation - Locations UI - Flutter Create powerful animations in Flutter and use the hero animation for complex animations. ⚡  Social Media  Twit

null 3 Dec 11, 2021
Create your own custom SlideTransition combined with some animation in Flutter.

Create your own custom SlideTransition combined with some animation in Flutter.

Johannes Milke 7 Jun 21, 2022
Arisslidetransition - Create your own custom SlideTransition combined with some animation in Flutter

SlideTransition Animation - Flutter Create your own custom SlideTransition combi

Behruz Hurramov 1 Jan 9, 2022
Flutter's core Dropdown Button widget with steady dropdown menu and many options you can customize to your needs.

Flutter DropdownButton2 Intro Flutter's core Dropdown Button widget with steady dropdown menu and many options you can customize to your needs. Featur

AHMED ELSAYED 125 Jan 4, 2023
A simple animated circular menu for Flutter, Adjustable radius, colors, alignment, animation curve and animation duration.

A simple animated circular menu for Flutter, Adjustable radius, colors, alignment, animation curve and animation duration. pub package Getting Started

Hasan Mohammed 91 Dec 20, 2022
A Flutter package allows you to Showcase/Highlight your widgets step by step.

ShowCaseView A Flutter package allows you to Showcase/Highlight your widgets step by step. Preview Installing Add dependency to pubspec.yaml Get the l

kirill 0 Dec 8, 2022
A Flutter package to custom splash screen like change logo icon, logo animation, and splash screen background color.

Custom Splash Screen A Flutter package to custom splash screen: change logo icon, logo animation, and splash screen background color. (Custom from ani

tranhuycong 78 Sep 6, 2022
BKash-Ballance-Animation - BKash Ballance Animation For Flutter

BKash-Ballance-Animation before clone the GitHub repository please give a star o

Blackshadow Software Ltd 11 Sep 1, 2022