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

Added optional value to flutter_flow_choice_chips.dart #10

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
12 changes: 7 additions & 5 deletions lib/src/flutter_flow/flutter_flow_choice_chips.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart';
const double _kChoiceChipsHeight = 40.0;

class ChipData {
const ChipData(this.label, [this.iconData]);
const ChipData(this.label, [this.value = "", this.iconData]);
final String label;
final String value;
final IconData? iconData;
}

Expand Down Expand Up @@ -77,7 +78,8 @@ class _FlutterFlowChoiceChipsState extends State<FlutterFlowChoiceChips> {
children: [
...widget.options.map(
(option) {
final selected = choiceChipValues.contains(option.label);
final String value = option.value.isNotEmpty ? option.value : option.label;
final selected = choiceChipValues.contains(value);
final style = selected
? widget.selectedChipStyle
: widget.unselectedChipStyle;
Expand All @@ -88,13 +90,13 @@ class _FlutterFlowChoiceChipsState extends State<FlutterFlowChoiceChips> {
onSelected: (isSelected) {
if (isSelected) {
widget.multiselect
? choiceChipValues.add(option.label)
: choiceChipValues = [option.label];
? choiceChipValues.add(value)
: choiceChipValues = [value];
widget.onChanged(choiceChipValues);
setState(() {});
} else {
if (widget.multiselect) {
choiceChipValues.remove(option.label);
choiceChipValues.remove(value);
widget.onChanged(choiceChipValues);
setState(() {});
}
Expand Down