Last active
June 22, 2021 05:21
-
-
Save lesliearkorful/8c3b892bc269845554a65db5f202113a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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