angular.dart.tutorial icon indicating copy to clipboard operation
angular.dart.tutorial copied to clipboard

Fixed the bug where the rating couldn't be zero.

Open CelerityAbbottPC opened this issue 11 years ago • 1 comments

Review on Reviewable

CelerityAbbottPC avatar Jan 19 '15 22:01 CelerityAbbottPC

Hi Celebrity:

Thanks for the pull request. I'm not 100% sure that this is a bug.

Let's say that a recipe in the JSON array specifies 0 as the rating. That is, a recipe starts out with a rating of 0.

The starChar method will do the right thing: String starChar(int star) => rating == null || star > rating ? _STAR_OFF_CHAR : _STAR_ON_CHAR;

It returns _STAR_OFF_CHAR for each star because rating is less than even the lowest star int. (The stars[] always starts at 1.)

Now if a user clicks the first star and invokes handleClick(), "star == 1 && rating == 1" evaluates to false, so the method sets rating to 1 (the value of the first star).

void handleClick(int star) { rating = (star == 1 && rating == 1) ? 0 : star; }

What were you seeing that seemed like a bug?

darrencarlton avatar Mar 05 '15 16:03 darrencarlton