Skip to content

Commit 4576029

Browse files
committed
Created switchInput constructor for FormBuilderInput
1 parent 4da0ed9 commit 4576029

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

example/lib/main.dart

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class MyHomePage extends StatelessWidget {
2727
margin: EdgeInsets.all(15.0),
2828
child: FormBuilder(
2929
context,
30-
autovalidate: true,
30+
autovalidate: false,
3131
// showResetButton: true,
3232
// resetButtonContent: Text("Clear Form"),
3333
controls: [
@@ -71,6 +71,7 @@ class MyHomePage extends StatelessWidget {
7171
type: FormBuilderInput.TYPE_PHONE,
7272
attribute: "phone",
7373
label: "Phone",
74+
hint: "Including country code (+254)"
7475
//require: true,
7576
),
7677
FormBuilderInput.password(
@@ -88,6 +89,7 @@ class MyHomePage extends StatelessWidget {
8889
),
8990
FormBuilderInput.checkboxList(
9091
label: "The Languages of my people",
92+
hint: "The Languages of my people",
9193
attribute: "languages",
9294
require: false,
9395
value: ["Dart"],
@@ -120,6 +122,15 @@ class MyHomePage extends StatelessWidget {
120122
return "Accept terms to continue";
121123
}
122124
),
125+
FormBuilderInput.switchInput(
126+
label: "I accept the terms and conditions",
127+
attribute: "accept_terms_switch",
128+
hint: "Kindly make sure you've read all the terms and conditions",
129+
validator: (value){
130+
if(!value)
131+
return "Accept terms to continue";
132+
}
133+
),
123134
FormBuilderInput.slider(
124135
label: "Slider",
125136
attribute: "slider",
@@ -140,7 +151,7 @@ class MyHomePage extends StatelessWidget {
140151
FormBuilderInput.rate(
141152
label: "Rate",
142153
attribute: "rate",
143-
iconSize: 48.0,
154+
iconSize: 32.0,
144155
value: 1,
145156
max: 5,
146157
hint: "Hint",

lib/src/form_builder_input.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,18 @@ class FormBuilderInput {
190190
type = FormBuilderInput.TYPE_CHECKBOX;
191191
}
192192

193+
FormBuilderInput.switchInput({
194+
@required this.label,
195+
@required this.attribute,
196+
this.hint,
197+
this.value,
198+
this.require = false,
199+
this.validator,
200+
}) : assert(value == null || value is bool,
201+
"Initial value for a switch should be boolean") {
202+
type = FormBuilderInput.TYPE_SWITCH;
203+
}
204+
193205
FormBuilderInput.checkboxList({
194206
@required this.label,
195207
@required this.options,

lib/src/form_builder_type_ahead.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class _FormBuilderTypeAheadState extends State<FormBuilderTypeAhead> {
3535
textFieldConfiguration: TextFieldConfiguration(
3636
controller: _typeAheadController,
3737
decoration: InputDecoration(
38-
labelText: formControl.label ?? formControl.attribute,
38+
labelText: formControl.label,
3939
),
4040
),
4141
suggestionsCallback: formControl.suggestionsCallback,

0 commit comments

Comments
 (0)