Skip to content

Instantly share code, notes, and snippets.

@lesliearkorful
Last active June 22, 2021 05:21
Show Gist options
  • Save lesliearkorful/8c3b892bc269845554a65db5f202113a to your computer and use it in GitHub Desktop.
Save lesliearkorful/8c3b892bc269845554a65db5f202113a to your computer and use it in GitHub Desktop.
class StarRating extends StatelessWidget {
final int stars;
final Color color;
final double iconSize;
const StarRating({Key key, this.stars = 0, this.color, this.iconSize})
: assert(stars >= 0 && stars <= 5),
super(key: key);
@override
Widget build(BuildContext context) {
final full = List.generate(stars, (_) => Icon(Icons.star));
final empty = List.generate(5 - stars, (_) => Icon(Icons.star_border));
return IconTheme(
data: IconThemeData(color: color, size: iconSize),
child: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [...full, ...empty],
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment