filterChipField method

String filterChipField(
  1. String elementName,
  2. String type,
  3. Map<String, dynamic> map, {
  4. String? parent,
})

Implementation

String filterChipField(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 FilterChip(
              $properties
              label:  Text(value.toString().split('.').last),
              selected: _selectedValue == value.toString().split('.').last,
              onSelected: (bool selected) {gene
                _selectedValue = value.toString().split('.').last;
                onSaved('${elementName}', value);
              },
            );
          }).toList()
    ''';
  } else {
    items = '[' + (map['options'] as List<Map<String, dynamic>>).map((e) => '''FilterChip(
              $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
    );
    ''';
}