Flutter GestureDetector and SmoothStarRaiting
Which version of the package are you using? I assume it's below v1.1.0
, as your code contains the now-removed onRatingChanged
callback.
If I understand your question correctly: you perform an expensive operation on rating changed event, so you need to debounce the events.
If my assessment is correct, it's pretty simple: you need to upgrade the package to v1.1.0, as it changes the behavior of onRated
, effectively debouncing it:
onRated will be called only once for each rating action.For a rating value n , the onRated callback value when half star rating is enabled will be n.5 . Eg: 2.5,3.5 etc.Otherwise the onRated callback value will be n.
Note: the name of the callback has changed to onRated
(from onRatingChanged
). Otherwise, your code should work fine.
Elisabetta
Updated on December 25, 2022Comments
-
Elisabetta over 1 year
Im facing an issue with GestureDetector wrapping SmoothStarRating, for some strange reason onHorizontalDragEnd doesn't work. I am able to detect only onTap or onLongPressEnd. onRatingChanged works well, but it calls BE multiple times while dragging and updating a rating. That's why I wrapped that with GestureDetector(to update the rating only when the drag is finished). Does anyone have an idea how to solve this?
I attach a code snippet below.
GestureDetector( onHorizontalDragEnd: (detail){ print("on drug end doesnt work"); // when drug is finished update record in DB }, onLongPressEnd: (detail){ print("this works"); }, child: Container( child: SmoothStarRating( allowHalfRating: true, onRatingChanged: (v) { // sending Bloc event to update raiting }, starCount: 5, rating: (rating),
-
Elisabetta over 3 yearsI have updated the version of the package to 1.1.0 as you suggested. But unfortunately, it didn't solve my problem. The behavior onRated is the same, the BE is called multiple times while I dragging upon the starts. In my case, it's not acceptable, because BE sends background notifications.... so the user would receive many notifications instead of one.
-
Elisabetta over 3 yearsThe thing is when I set isReadOnly property of star rating = true. OnPanEnd and OnDrugEnd of GestureDetector work just fine. So I guess there is a conflict and that's why I can't use both
-
Riwen over 3 yearsSmoothStarRaiting handles horizontal dragging (if not readonly), so you cannot really use it. Your best bet would be debouncing the result of
onRated
. Or if you really want to handle dragging by yourself, just take a look at the code, make it yours and change it. -
Elisabetta over 3 yearsWith debouncing worked just fine! Thank you)))))