Skip to content

Commit 85ee48b

Browse files
committed
Added documentation for FormBuilder & FormBuilderField attributes
1 parent fa71d44 commit 85ee48b

File tree

2 files changed

+65
-15
lines changed

2 files changed

+65
-15
lines changed

lib/src/form_builder.dart

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,45 @@ class FormBuilderState extends FormState {
6666
}*/
6767

6868
class FormBuilder extends StatefulWidget {
69-
//final BuildContext context;
70-
final Function(Map<String, dynamic>) onChanged;
69+
/// Called when one of the form fields changes.
70+
///
71+
/// In addition to this callback being invoked, all the form fields themselves
72+
/// will rebuild.
73+
final VoidCallback onChanged;
74+
75+
/// Enables the form to veto attempts by the user to dismiss the [ModalRoute]
76+
/// that contains the form.
77+
///
78+
/// If the callback returns a Future that resolves to false, the form's route
79+
/// will not be popped.
80+
///
81+
/// See also:
82+
///
83+
/// * [WillPopScope], another widget that provides a way to intercept the
84+
/// back button.
7185
final WillPopCallback onWillPop;
86+
87+
/// The widget below this widget in the tree.
88+
///
89+
/// This is the root of the widget hierarchy that contains this form.
90+
///
91+
/// {@macro flutter.widgets.child}
7292
final Widget child;
93+
94+
/// Whether the field value can be changed. Defaults to false.
95+
/// If true, all form fields will not accept user input.
7396
final bool readOnly;
97+
98+
/// If true, form fields will validate and update their error text
99+
/// immediately after every change. Otherwise, you must call
100+
/// [FormState.validate] to validate.
74101
final bool autovalidate;
102+
103+
/// An optional Map of field initialValues. Keys correspond to the field's
104+
/// attribute and value to the initialValue of the field.
105+
///
106+
/// The initialValues set here will be ignored if the field has a local
107+
/// initialValue set.
75108
final Map<String, dynamic> initialValue;
76109

77110
const FormBuilder({
@@ -135,16 +168,6 @@ class FormBuilderState extends State<FormBuilder> {
135168
_fieldKeys.remove(attribute);
136169
}
137170

138-
/*changeAttributeValue(String attribute, dynamic newValue) {
139-
print(this.fieldKeys[attribute]);
140-
if (this.fieldKeys[attribute] != null){
141-
print("Current $attribute value: ${this.fieldKeys[attribute].currentState.value}");
142-
print("Trying to change $attribute to $newValue");
143-
this.fieldKeys[attribute].currentState.didChange(newValue);
144-
print("$attribute value after: ${this.fieldKeys[attribute].currentState.value}");
145-
}
146-
}*/
147-
148171
void save() {
149172
_formKey.currentState.save();
150173
}
@@ -172,9 +195,7 @@ class FormBuilderState extends State<FormBuilder> {
172195
),
173196
autovalidate: widget.autovalidate,
174197
onWillPop: widget.onWillPop,
175-
onChanged: () {
176-
widget.onChanged?.call(value);
177-
},
198+
onChanged: widget.onChanged,
178199
);
179200
}
180201
}

lib/src/form_builder_field.dart

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,41 @@ import 'package:flutter/scheduler.dart';
33
import 'package:flutter_form_builder/flutter_form_builder.dart';
44

55
class FormBuilderField<T> extends FormField<T> {
6+
/// Used to reference the field within the form, or to reference form data
7+
/// after the form is submitted.
68
final String attribute;
9+
10+
/// Called just before field value is saved. Used to massage data just before
11+
/// committing the value.
12+
///
13+
/// This sample shows how to convert age in a [FormBuilderTextField] to number
14+
/// so that the final value is numeric instead of a String
15+
///
16+
/// ```dart
17+
/// FormBuilderTextField(
18+
/// attribute: 'age',
19+
/// decoration: InputDecoration(labelText: 'Age'),
20+
/// valueTransformer: (text) => num.tryParse(text),
21+
/// validator: FormBuilderValidators.numeric(context),
22+
/// initialValue: '18',
23+
/// keyboardType: TextInputType.number,
24+
/// ),
25+
/// ```
726
final ValueTransformer valueTransformer;
27+
28+
/// Called when the field value is changed.
829
final ValueChanged<T> onChanged;
30+
31+
/// Whether the field value can be changed. Defaults to false
932
final bool readOnly;
33+
34+
/// The border, labels, icons, and styles used to decorate the field.
1035
final InputDecoration decoration;
36+
37+
/// Called when the field value is reset.
1138
final VoidCallback onReset;
39+
40+
/// {@macro flutter.widgets.Focus.focusNode}
1241
final FocusNode focusNode;
1342

1443
FormBuilderField({

0 commit comments

Comments
 (0)