Skip to content

Commit

Permalink
Rated stars/icons can now be changed
Browse files Browse the repository at this point in the history
default size(25) given to icons inorder to prevent "The method 'toDouble' was called on null" exception
  • Loading branch information
thangmam committed Dec 26, 2019
1 parent 01c950f commit 52a8a9b
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions lib/smooth_star_rating.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,42 @@ class SmoothStarRating extends StatelessWidget {
final Color borderColor;
final double size;
final bool allowHalfRating;

SmoothStarRating(
{this.starCount = 5,
this.rating = 0.0,
this.onRatingChanged,
this.color,
this.borderColor,
this.size,
this.allowHalfRating = true}) {
final IconData fullRatedIconData;
final IconData halfRatedIconData;
SmoothStarRating({
this.starCount = 5,
this.rating = 0.0,
this.onRatingChanged,
this.color,
this.borderColor,
this.size = 25,
this.fullRatedIconData,
this.halfRatedIconData,
this.allowHalfRating = true,
}) {
assert(this.rating != null);
}

Widget buildStar(BuildContext context, int index) {
Icon icon;
if (index >= rating) {
icon = new Icon(
Icons.star_border,
fullRatedIconData != null ? fullRatedIconData : Icons.star_border,
color: borderColor ?? Theme.of(context).primaryColor,
size: size ?? 25.0,
size: size,
);
} else if (index > rating - (allowHalfRating ? 0.5 : 1.0) &&
index < rating) {
icon = new Icon(
Icons.star_half,
halfRatedIconData != null ? halfRatedIconData : Icons.star_half,
color: color ?? Theme.of(context).primaryColor,
size: size ?? 25.0,
size: size,
);
} else {
icon = new Icon(
Icons.star,
fullRatedIconData != null ? fullRatedIconData : Icons.star,
color: color ?? Theme.of(context).primaryColor,
size: size ?? 25.0,
size: size,
);
}

Expand Down

0 comments on commit 52a8a9b

Please sign in to comment.