Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
# Conflicts:
#	lib/smooth_star_rating.dart
  • Loading branch information
thangmam committed Dec 26, 2019
2 parents 160de63 + cb87e99 commit 3f9c503
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
2 changes: 2 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class _MyAppState extends State<MyApp> {
child: SmoothStarRating(
rating: rating,
size: 45,
fullRatedIconData: Icons.bluetooth_audio,
halfRatedIconData: Icons.bluetooth_connected,
starCount: 5,
spacing: 2.0,
onRatingChanged: (value) {
Expand Down
37 changes: 20 additions & 17 deletions lib/smooth_star_rating.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
library smooth_star_rating;

import 'package:flutter/material.dart';
import 'package:flutter/material.dart';

typedef void RatingChangeCallback(double rating);
Expand All @@ -12,40 +13,42 @@ class SmoothStarRating extends StatelessWidget {
final Color borderColor;
final double size;
final bool allowHalfRating;
final double spacing;

SmoothStarRating(
{this.starCount = 5,
this.rating = 0.0,
this.onRatingChanged,
this.color,
this.borderColor,
this.size,
this.spacing = 0.0,
this.allowHalfRating = true}) {
final IconData fullRatedIconData;
final IconData halfRatedIconData;
SmoothStarRating({
this.starCount = 5,
this.rating = 0.0,
this.onRatingChanged,
this.color,
this.borderColor,
this.size = 25,
this.fullRatedIconData,
this.halfRatedIconData,
this.allowHalfRating = true,
}) {
assert(this.rating != null);
}

Widget buildStar(BuildContext context, int index) {
Icon icon;
if (index >= rating) {
icon = new Icon(
Icons.star_border,
fullRatedIconData != null ? fullRatedIconData : Icons.star_border,
color: borderColor ?? Theme.of(context).primaryColor,
size: size ?? 25.0,
size: size,
);
} else if (index > rating - (allowHalfRating ? 0.5 : 1.0) &&
index < rating) {
icon = new Icon(
Icons.star_half,
halfRatedIconData != null ? halfRatedIconData : Icons.star_half,
color: color ?? Theme.of(context).primaryColor,
size: size ?? 25.0,
size: size,
);
} else {
icon = new Icon(
Icons.star,
fullRatedIconData != null ? fullRatedIconData : Icons.star,
color: color ?? Theme.of(context).primaryColor,
size: size ?? 25.0,
size: size,
);
}

Expand Down

0 comments on commit 3f9c503

Please sign in to comment.