1
1
import 'package:flutter/material.dart' ;
2
2
import 'package:flutter/widgets.dart' ;
3
3
import 'package:flutter_form_builder/flutter_form_builder.dart' ;
4
- import 'package:group_radio_button/group_radio_button.dart' ;
4
+ import 'package:flutter_form_builder/src/widgets/grouped_checkbox.dart' ;
5
+ import 'package:flutter_form_builder/src/widgets/grouped_radio.dart' ;
5
6
6
7
class FormBuilderRadioGroup extends StatefulWidget {
7
8
final String attribute;
@@ -12,15 +13,29 @@ class FormBuilderRadioGroup extends StatefulWidget {
12
13
final ValueChanged onChanged;
13
14
final ValueTransformer valueTransformer;
14
15
15
- final bool leadingInput;
16
16
final List <FormBuilderFieldOption > options;
17
17
final MaterialTapTargetSize materialTapTargetSize;
18
18
final Color activeColor;
19
19
final FormFieldSetter onSaved;
20
- final EdgeInsets contentPadding;
21
- final Axis direction;
22
- final MainAxisAlignment horizontalAlignment;
23
- final double spaceBetween;
20
+ final Color focusColor;
21
+ final Color hoverColor;
22
+ final List disabled;
23
+ final Axis wrapDirection;
24
+ final WrapAlignment wrapAlignment;
25
+
26
+ final double wrapSpacing;
27
+
28
+ final WrapAlignment wrapRunAlignment;
29
+
30
+ final double wrapRunSpacing;
31
+
32
+ final WrapCrossAlignment wrapCrossAxisAlignment;
33
+
34
+ final VerticalDirection wrapVerticalDirection;
35
+ final TextDirection wrapTextDirection;
36
+ final Widget separator;
37
+ final ControlAffinity controlAffinity; // = ControlAffinity.leading;
38
+ final GroupedRadioOrientation orientation; // = GroupedRadioOrientation.wrap;
24
39
25
40
FormBuilderRadioGroup ({
26
41
Key key,
@@ -32,14 +47,23 @@ class FormBuilderRadioGroup extends StatefulWidget {
32
47
this .decoration = const InputDecoration (),
33
48
this .onChanged,
34
49
this .valueTransformer,
35
- this .leadingInput = false ,
50
+ this .onSaved ,
36
51
this .materialTapTargetSize,
52
+ this .wrapDirection = Axis .horizontal,
53
+ this .wrapAlignment = WrapAlignment .start,
54
+ this .wrapSpacing = 0.0 ,
55
+ this .wrapRunAlignment = WrapAlignment .start,
56
+ this .wrapRunSpacing = 0.0 ,
57
+ this .wrapCrossAxisAlignment = WrapCrossAlignment .start,
58
+ this .wrapVerticalDirection = VerticalDirection .down,
59
+ this .controlAffinity = ControlAffinity .leading,
60
+ this .orientation = GroupedRadioOrientation .wrap,
37
61
this .activeColor,
38
- this .onSaved ,
39
- this .contentPadding = const EdgeInsets . all ( 0.0 ) ,
40
- this .direction = Axis .horizontal ,
41
- this .horizontalAlignment = MainAxisAlignment .start ,
42
- this .spaceBetween ,
62
+ this .focusColor ,
63
+ this .hoverColor ,
64
+ this .disabled ,
65
+ this .wrapTextDirection ,
66
+ this .separator ,
43
67
}) : super (key: key);
44
68
45
69
@override
@@ -87,37 +111,39 @@ class _FormBuilderRadioGroupState extends State<FormBuilderRadioGroup> {
87
111
} else {
88
112
_formState? .setAttributeValue (widget.attribute, val);
89
113
}
90
- if (widget.onSaved != null ) {
91
- widget.onSaved (transformed ?? val);
92
- }
114
+ widget.onSaved? .call (transformed ?? val);
93
115
},
94
116
builder: (FormFieldState <dynamic > field) {
95
117
return InputDecorator (
96
118
decoration: widget.decoration.copyWith (
97
119
enabled: ! _readOnly,
98
120
errorText: field.errorText,
99
121
),
100
- child: RadioGroup .builder (
101
- groupValue: field.value,
102
- onChanged: _readOnly
103
- ? null
104
- : (value) {
105
- FocusScope .of (context).requestFocus (FocusNode ());
106
- field.didChange (value);
107
- widget.onChanged? .call (value);
108
- },
109
- items: widget.options
110
- .map ((option) => option.value)
111
- .toList (growable: false ),
112
- itemBuilder: (item) {
113
- return RadioButtonBuilder (
114
- item.toString (),
115
- textPosition: RadioButtonTextPosition .right,
116
- );
122
+ child: GroupedRadio (
123
+ orientation: widget.orientation,
124
+ value: field.value,
125
+ options: widget.options,
126
+ onChanged: (val) {
127
+ field.didChange (val);
128
+ widget.onChanged? .call (val);
117
129
},
118
- direction: widget.direction,
119
- horizontalAlignment: widget.horizontalAlignment,
120
- spacebetween: widget.spaceBetween,
130
+ activeColor: widget.activeColor,
131
+ focusColor: widget.focusColor,
132
+ materialTapTargetSize: widget.materialTapTargetSize,
133
+ disabled: ! _readOnly
134
+ ? widget.disabled
135
+ : widget.options.map ((e) => e.value).toList (),
136
+ hoverColor: widget.hoverColor,
137
+ wrapAlignment: widget.wrapAlignment,
138
+ wrapCrossAxisAlignment: widget.wrapCrossAxisAlignment,
139
+ wrapDirection: widget.wrapDirection,
140
+ wrapRunAlignment: widget.wrapRunAlignment,
141
+ wrapRunSpacing: widget.wrapRunSpacing,
142
+ wrapSpacing: widget.wrapSpacing,
143
+ wrapTextDirection: widget.wrapTextDirection,
144
+ wrapVerticalDirection: widget.wrapVerticalDirection,
145
+ separator: widget.separator,
146
+ controlAffinity: widget.controlAffinity,
121
147
),
122
148
);
123
149
},
0 commit comments