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

feat(YaruChoiceChipBar): add selectedFirst parameter #827

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions example/lib/pages/choice_chip_bar_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class _ChoiceChipBarPageState extends State<ChoiceChipBarPage> {
child: Column(
children: [
YaruChoiceChipBar(
selectedFirst: false,
showCheckMarks: false,
shrinkWrap: true,
clearOnSelect: false,
Expand Down
21 changes: 15 additions & 6 deletions lib/src/widgets/yaru_choice_chip_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class YaruChoiceChipBar extends StatefulWidget {
this.clearOnSelect = true,
this.shrinkWrap = true,
this.showCheckMarks = true,
this.selectedFirst = true,
}) : assert(labels.length == isSelected.length);

/// The [List] of [Widget]'s used to generate a [List] of [ChoiceChip]s
Expand Down Expand Up @@ -113,6 +114,9 @@ class YaruChoiceChipBar extends StatefulWidget {
/// The default is `true`.
final bool showCheckMarks;

/// Defines if the selected [ChoiceChip]s should be always placed first.
final bool selectedFirst;

@override
State<YaruChoiceChipBar> createState() => _YaruChoiceChipBarState();
}
Expand Down Expand Up @@ -187,12 +191,17 @@ class _YaruChoiceChipBarState extends State<YaruChoiceChipBar> {
);
}

final children = [
for (int index = 0; index < widget.labels.length; index++)
if (widget.isSelected[index]) themedChip(index),
for (int index = 0; index < widget.labels.length; index++)
if (!widget.isSelected[index]) themedChip(index),
];
final children = widget.selectedFirst
? [
for (int index = 0; index < widget.labels.length; index++)
if (widget.isSelected[index]) themedChip(index),
for (int index = 0; index < widget.labels.length; index++)
if (!widget.isSelected[index]) themedChip(index),
]
: [
for (int index = 0; index < widget.labels.length; index++)
themedChip(index),
];

final listView = ListView(
shrinkWrap: widget.shrinkWrap,
Expand Down