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

Addd separator #90

Open
wants to merge 3 commits 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
20 changes: 19 additions & 1 deletion lib/src/rating_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class RatingBar extends StatefulWidget {
this.ignoreGestures = false,
this.initialRating = 0.0,
this.itemCount = 5,
this.separator = const SizedBox(),
this.itemPadding = EdgeInsets.zero,
this.itemSize = 40.0,
this.minRating = 0,
Expand Down Expand Up @@ -77,6 +78,7 @@ class RatingBar extends StatefulWidget {
this.ignoreGestures = false,
this.initialRating = 0.0,
this.itemCount = 5,
this.separator = const SizedBox(),
this.itemPadding = EdgeInsets.zero,
this.itemSize = 40.0,
this.minRating = 0,
Expand Down Expand Up @@ -150,6 +152,10 @@ class RatingBar extends StatefulWidget {
/// Default is 5.
/// {@endtemplate}
final int itemCount;

/// {@template flutterRatingBar.separator}
/// A separator widget between each rating item.
final Widget separator;

/// {@template flutterRatingBar.itemPadding}
/// The amount of space by which to inset each rating item.
Expand Down Expand Up @@ -244,7 +250,7 @@ class _RatingBarState extends State<RatingBar> {
children: List.generate(
widget.itemCount,
(index) => _buildRating(context, index),
),
)._addBetween(widget.separator),
),
);
}
Expand Down Expand Up @@ -508,3 +514,15 @@ class _NoRatingWidget extends StatelessWidget {
);
}
}

extension _ListExtension<T> on List<T> {
/// Insert [item] between each member of this list
List<T> _addBetween(T item) {
if (length > 1) {
for (int i = length - 1; i > 0; i--) {
insert(i, item);
}
}
return this;
}
}