Skip to content

Commit 26879e9

Browse files
committed
Add custom filter chip option to accept avatar
1 parent 881879b commit 26879e9

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

packages/flutter_form_builder/lib/flutter_form_builder.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ export 'src/fields/form_builder_switch.dart';
1818
export 'src/fields/form_builder_text_field.dart';
1919
export 'src/widgets/grouped_checkbox.dart';
2020
export 'src/widgets/grouped_radio.dart';
21+
export 'src/options/form_builder_filter_chips_option.dart';

packages/flutter_form_builder/lib/src/fields/form_builder_filter_chips.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class FormBuilderFilterChip<T> extends FormBuilderField<List<T>> {
1212
final Color? selectedShadowColor;
1313
final Color? shadowColor;
1414
final double? elevation, pressElevation;
15-
final List<FormBuilderFieldOption<T>> options;
15+
final List<FormBuilderFilterChipsOption<T>> options;
1616
final MaterialTapTargetSize? materialTapTargetSize;
1717
final OutlinedBorder? shape;
1818

@@ -102,10 +102,11 @@ class FormBuilderFilterChip<T> extends FormBuilderField<List<T>> {
102102
textDirection: textDirection,
103103
verticalDirection: verticalDirection,
104104
children: <Widget>[
105-
for (FormBuilderFieldOption<T> option in options)
105+
for (FormBuilderFilterChipsOption<T> option in options)
106106
FilterChip(
107107
label: option,
108108
selected: field.value!.contains(option.value),
109+
avatar: option.avatar,
109110
onSelected: state.enabled &&
110111
(null == maxChips ||
111112
field.value!.length < maxChips ||
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_form_builder/flutter_form_builder.dart';
3+
4+
/// An option for filter chips.
5+
///
6+
/// The type `T` is the type of the value the entry represents. All the entries
7+
/// in a given menu must represent values with consistent types.
8+
class FormBuilderFilterChipsOption<T> extends FormBuilderFieldOption<T> {
9+
final Widget? avatar;
10+
11+
/// Creates an option for fields with selection options
12+
const FormBuilderFilterChipsOption({
13+
Key? key,
14+
required value,
15+
this.avatar,
16+
child,
17+
}) : super(
18+
key: key,
19+
value: value,
20+
child: child,
21+
);
22+
23+
@override
24+
Widget build(BuildContext context) {
25+
return child ?? Text(value.toString());
26+
}
27+
}

0 commit comments

Comments
 (0)