like_button icon indicating copy to clipboard operation
like_button copied to clipboard

Like Status resetting when scrolling away

Open supidupicoder opened this issue 2 years ago • 7 comments

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;
                    },
                  ),
                ],
              ))
            ],
          ),
        )

supidupicoder avatar Aug 16 '21 09:08 supidupicoder

save by yourself

zmtzawqlp avatar Aug 16 '21 09:08 zmtzawqlp

hello can you specify what exactly you mean by that? _currentlyAnsweredNotification.liked is saved by myself (as far as i understand it).

or do you mean ignoring the built-in isLiked property all together and using my own _currentlyAnsweredNotification.liked parameter at all times?

supidupicoder avatar Aug 16 '21 09:08 supidupicoder

class A { bool isLiked=false; }

save status by data not the ui

zmtzawqlp avatar Aug 16 '21 11:08 zmtzawqlp

Hello,

i think i do not understand your suggestion correctly.

i do save the isLiked state in a class/object namely _currentlyAnsweredNotification _currentlyAnsweredNotification is not overriden by the UI, _currentlyAnsweredNotification.isLiked stays true, even when the likeButton is destroyed.

but upon rebuild, the likeBuilder seems to be using the isLiked value which was used upon creation. _currentlyAnsweredNotification.isLiked is true when likeBuilder is called again, but the "isLiked" property passed to the likeBuilder is still false. i think this is due to _currentlyAnsweredNotification.isLiked being false when the LikeButton was created (so only the false value is saved, no reference to _currentlyAnsweredNotification.isLiked).

How to fix this?

is class A the equivalent to my _currentlyAnsweredNotification ? where am i supposed to place class a/how am i supposed to use it?

supidupicoder avatar Aug 16 '21 11:08 supidupicoder

Team,I also have the same issue with the List View when scrolling it out of view, and back again the status resets. , Could you please provide an simple example on this please

jacksondmello avatar Aug 19 '21 06:08 jacksondmello

 class A {
  bool isLiked = false;
}
    List<A> list = List<A>.filled(1000, A());
    ListView.builder(
      itemBuilder: (b, index) {
        var item = list[index];
        return LikeButton(
          isLiked: item.isLiked,
          onTap: (bool isLiked) async {
            item.isLiked = !item.isLiked;
            return item.isLiked;
          },
        );
      },
    );

zmtzawqlp avatar Aug 19 '21 12:08 zmtzawqlp

 var item = list[index];

Video Like is working as expected is there any way to persistent likecounts?

SR-INGENIOUSMINDSLAB avatar Jan 31 '22 07:01 SR-INGENIOUSMINDSLAB

 var item = list[index];

Video Like is working as expected is there any way to persistent likecounts?

the same way, in count builder

zmtzawqlp avatar Sep 29 '22 06:09 zmtzawqlp