You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
fluffychat/lib/pangea/widgets/common/star_rating.dart

57 lines
1.3 KiB
Dart

import 'package:flutter/material.dart';
typedef RatingChangeCallback = void Function(double rating);
class StarRating extends StatelessWidget {
final int starCount;
final double rating;
final RatingChangeCallback? onRatingChanged;
final Color color;
const StarRating({
super.key,
this.starCount = 5,
this.rating = 0,
this.onRatingChanged,
required this.color,
});
Widget buildStar(BuildContext context, int index) {
Icon icon;
if (index >= rating) {
icon = const Icon(
Icons.star_border,
size: 20,
color: Color(0xffFFC403),
);
} else if (index > rating - 1 && index < rating) {
icon = Icon(
Icons.star_half,
color: color,
//?? Theme.of(context).primaryColor,
size: 20,
);
} else {
icon = Icon(
Icons.star,
color: color,
//?? Theme.of(context).primaryColor,
size: 20,
);
}
return InkResponse(
onTap:
onRatingChanged == null ? null : () => onRatingChanged!(index + 1.0),
child: icon,
);
}
@override
Widget build(BuildContext context) {
return Row(
mainAxisSize: MainAxisSize.min,
children: List.generate(starCount, (index) => buildStar(context, index)),
);
}
}