buildRatingStar static method

Widget buildRatingStar({
  1. double rating = 5,
  2. Color activeColor = starColor,
  3. Color inactiveColor = starColor,
  4. double? size = 16,
  5. double spacing = 0,
  6. bool inactiveStarFilled = false,
  7. bool showInactive = true,
})

Implementation

static Widget buildRatingStar(
    {double rating = 5,
    Color activeColor = starColor,
    Color inactiveColor = starColor,
    double? size = 16,
    double spacing = 0,
    bool inactiveStarFilled = false,
    bool showInactive = true}) {
  int ratingCount = rating.floor();
  bool isHalf = (ratingCount != rating);
  List<Widget> _stars = [];
  for (int i = 0; i < 5; i++) {
    if (i < ratingCount) {
      _stars.add(Icon(
        Icons.star,
        color: activeColor,
        size: size,
      ));

      _stars.add(SizedBox(width: spacing));
    } else {
      if (isHalf) {
        isHalf = false;
        _stars.add(Icon(
          Icons.star_half,
          color: activeColor,
          size: size,
        ));
      } else if (showInactive) {
        _stars.add(Icon(
          inactiveStarFilled ? Icons.star : Icons.star_outline,
          color: inactiveColor,
          size: size,
        ));
      }
      _stars.add(SizedBox(width: spacing));
    }
  }
  return Row(mainAxisSize: MainAxisSize.min, children: _stars);
}