GeekAbdelouahed / flutter-reaction-button

Flutter Reaction Button is a customizable Flutter package that allows you to easily create interactive buttons with reaction emojis, similar to Facebook's iconic reaction buttons.
https://pub.dev/packages/flutter_reaction_button
MIT License
215 stars 78 forks source link

Reactions Are Never Turned Off #23

Closed rlee1990 closed 3 years ago

rlee1990 commented 3 years ago

When I try to remove a reaction that I already selected it just sets it to the first reaction. Checking if isChecked always returns true.

 FlutterReactionButtonCheck(
          onReactionChanged: (reaction, index, isChecked) {
            print('click: $index');
            if (isChecked) {
              print(isChecked);
              if (!_likeExists(widget.post!.likeReactions)) {
                setState(() {
                  selectedReation = reaction;
                  widget.streamClient!.reactions.add('like', widget.post!.id!,
                      userId: widget.streamClient!.currentUser!.userId,
                      data: {
                        'value': index,
                      });
                  widget.post!.likesCount = widget.post!.likesCount! + 1;
                  StreamAPI().sendLikeNotificationPost(
                      widget.streamClient!,
                      widget.streamClient!.currentUser!.userId,
                      widget.post!.owner,
                      widget.post!.id,
                      index);
                });
              } else if (_likeExists(widget.post!.likeReactions)) {
                setState(() {
                  selectedReation = reaction;
                  widget.streamClient!.reactions.update(like.likeId!, data: {
                    'value': index,
                  });
                });
              }
            } else {
              if (_likeExists(widget.post!.likeReactions)) {
                setState(() {
                  selectedReation = reaction;
                  widget.streamClient!.reactions.delete(like.likeId!);
                  widget.post!.likesCount = widget.post!.likesCount! - 1;
                });
              }
            }
          },
          isChecked: selectedReation != null ? true : false,
          reactions: SNAB().reactions,
          initialReaction: _likeExists(widget.post!.likeReactions)
              ? SNAB().reactions[like.value!]
              : Reaction(
                  id: 7,
                  icon: Image.asset(
                    'assets/images/100.png',
                    height: 20,
                    color: Colors.grey[600],
                  )),
          selectedReaction: selectedReation,
        ),
rlee1990 commented 3 years ago

Sorry was using the isChecked field wrong.