choiceChipField method
Implementation
String choiceChipField(String elementName, String type, Map<String, dynamic> map, {String? parent}) {
String items;
// choicechip properties
final properties = '''
autofocus: ${map['autofocus'] ?? false},
avatar: ${map['avatar']},
${map['avatarBorder'] != null ? 'avatarBorder:${map['avatarBorder']})' : ''}
backgroundColor: ${map['backgroundColor']},
${map['clipBehinity'] != null ? 'clipBehinity:${map['clipBehinity']})' : ''}
disabledColor: ${map['disabledColor']},
elevation: ${map['elevation']},
${map['focusNode'] != null ? 'focusNode: FocusNode(),\n' : ''}
labelPadding: ${map['labelPadding']},
labelStyle: ${map['labelStyle']},
materialTapTargetSize: ${map['materialTapTargetSize']},
padding: ${map['padding']},
pressElevation: ${map['pressElevation']},
selectedColor: ${map['selectedColor']},
selectedShadowColor: ${map['selectedShadowColor']},
shape: ${map['shape']},
side: ${map['side']},
tooltip: ${map['tooltip']},
visualDensity: ${map['visualDensity']},
''';
if (map['type'] == 'enum') {
items = '''
${type}.values.map((value) {
return ChoiceChip(
$properties
label: Text(value.toString().split('.').last),
selected: _selectedValue == value.toString().split('.').last,
onSelected: (bool selected) {
_selectedValue = value.toString().split('.').last;
onSaved('${elementName}', value);
},
);
}).toList()
''';
} else {
items = '[' + (map['options'] as List<Map<String, dynamic>>).map((e) => '''ChoiceChip(
$properties
label: Text("${e['label'] ?? e['value'].toString()}"),
selected: _selectedValue == "${e['value'].toString()}",
onSelected: (bool selected) {
_selectedValue = "${e['value'].toString()}";
onSaved('${elementName}', "${e['value'].toString()}");
},
)''').toList().join(',\n') + ']';
}
return '''
var _selectedValue = _formData['${elementName}'];
return Wrap(
children: $items
);
''';
}