Skip to content

Commit aae9e93

Browse files
committed
Converted FormBuilderFieldOption to Widget - allows option to be customized/styled
1 parent c4c206c commit aae9e93

File tree

4 files changed

+29
-14
lines changed

4 files changed

+29
-14
lines changed

lib/src/fields/form_builder_checkbox_list.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ class _FormBuilderCheckboxListState extends State<FormBuilderCheckboxList> {
126126
contentPadding: EdgeInsets.all(0.0),
127127
leading: _leading(field, i),
128128
trailing: _trailing(field, i),
129-
title: Text(
130-
"${widget.options[i].label ?? widget.options[i].value}"),
129+
title: widget.options[i],
131130
onTap: _readOnly
132131
? null
133132
: () {

lib/src/fields/form_builder_radio.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ class _FormBuilderRadioState extends State<FormBuilderRadio> {
116116
isThreeLine: false,
117117
contentPadding: EdgeInsets.all(0.0),
118118
leading: _leading(field, i),
119-
title:
120-
Text("${widget.options[i].label ?? widget.options[i].value}"),
119+
title: widget.options[i],
121120
trailing: _trailing(field, i),
122121
onTap: _readOnly
123122
? null

lib/src/fields/form_builder_segmented_control.dart

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ class FormBuilderSegmentedControl extends StatefulWidget {
1414
final Color borderColor;
1515
final Color selectedColor;
1616
final Color pressedColor;
17+
18+
@Deprecated(
19+
"Use `FormBuilderFieldOption`'s `child` property to style your option")
1720
final TextStyle textStyle;
1821

1922
final List<FormBuilderFieldOption> options;
@@ -113,13 +116,15 @@ class _FormBuilderSegmentedControlState
113116
groupValue: field.value,
114117
children: Map.fromIterable(
115118
widget.options,
116-
key: (v) => v.value,
117-
value: (v) => Padding(
119+
key: (option) => option.value,
120+
value: (option) => Padding(
118121
padding: EdgeInsets.symmetric(vertical: 10.0),
119-
child: Text(
120-
"${v.label ?? v.value}",
121-
style: widget.textStyle,
122-
),
122+
child: widget.textStyle != null
123+
? Text(
124+
"${option.label ?? option.value}",
125+
style: widget.textStyle,
126+
)
127+
: option,
123128
),
124129
),
125130
padding: widget.padding,
Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
import 'package:flutter/material.dart';
22

3-
class FormBuilderFieldOption {
4-
String label;
5-
dynamic value;
3+
class FormBuilderFieldOption extends StatelessWidget {
4+
@Deprecated("Use `child` instead. Will be removed in the next major version.")
5+
final String label;
6+
final Widget child;
7+
final dynamic value;
68

7-
FormBuilderFieldOption({this.label, @required this.value});
9+
FormBuilderFieldOption({this.label, @required this.value, this.child})
10+
: assert(label == null || child == null);
11+
12+
@override
13+
Widget build(BuildContext context) {
14+
if (child != null) {
15+
return child;
16+
} else {
17+
return Text("${label ?? value.toString()}");
18+
}
19+
}
820
}

0 commit comments

Comments
 (0)