Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disabled same selected rating. #93

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/src/rating_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class RatingBar extends StatefulWidget {
this.tapOnlyMode = false,
this.updateOnDrag = false,
this.wrapAlignment = WrapAlignment.start,
this.disableSameSelected = false,
}) : _itemBuilder = null,
_ratingWidget = ratingWidget,
super(key: key);
Expand Down Expand Up @@ -80,6 +81,7 @@ class RatingBar extends StatefulWidget {
this.tapOnlyMode = false,
this.updateOnDrag = false,
this.wrapAlignment = WrapAlignment.start,
this.disableSameSelected = false,
}) : _itemBuilder = itemBuilder,
_ratingWidget = null,
super(key: key);
Expand Down Expand Up @@ -181,6 +183,11 @@ class RatingBar extends StatefulWidget {
/// Defaults to [WrapAlignment.start].
final WrapAlignment wrapAlignment;

/// Disable same selected rating star.
/// For example if same star is selected again
/// then on upDate will not trigger.
final bool disableSameSelected;

final IndexedWidgetBuilder? _itemBuilder;
final RatingWidget? _ratingWidget;

Expand Down Expand Up @@ -306,6 +313,9 @@ class _RatingBarState extends State<RatingBar> {
}

value = math.max(value, widget.minRating);
if(widget.disableSameSelected && _rating == value) {
return;
}
widget.onRatingUpdate(value);
_rating = value;
setState(() {});
Expand Down