buildStar method
Implementation
Widget buildStar(BuildContext context, int index) {
FaIcon icon;
// Calculate the difference between the index and current rating.
final double difference = _currentRating - index;
if (difference >= 0.75) {
icon = FaIcon(
FontAwesomeIcons.solidStar,
color: _getFilledColor(context),
size: widget.size,
);
} else if (difference >= 0.25) {
icon = FaIcon(
FontAwesomeIcons.solidStarHalfStroke,
color: _getFilledColor(context),
size: widget.size,
);
} else {
icon = buildStarIcon(context);
}
return GestureDetector(
onTap: () {
if (!widget.disabled && !widget.readOnly && mounted) {
setState(() {
_currentRating = index + 1;
widget.onRatingChanged?.call(_currentRating);
});
}
},
child: icon,
);
}