Skip to content

Commit 4e1a801

Browse files
committed
Added maxLines & autovalidate options to be used in textField input
1 parent 8c9c1f9 commit 4e1a801

File tree

3 files changed

+41
-30
lines changed

3 files changed

+41
-30
lines changed

example/lib/main.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class MyHomePage extends StatefulWidget {
2626
class MyHomePageState extends State<MyHomePage> {
2727
var data;
2828
bool autoValidate = true;
29+
bool readOnly = false;
2930

3031
@override
3132
Widget build(BuildContext context) {
@@ -311,7 +312,7 @@ class MyHomePageState extends State<MyHomePage> {
311312
context,
312313
// key: _fbKey,
313314
autovalidate: autoValidate,
314-
readonly: true,
315+
readonly: readOnly,
315316
// showResetButton: true,
316317
// resetButtonContent: Text("Clear Form"),
317318
controls: [
@@ -418,6 +419,15 @@ class MyHomePageState extends State<MyHomePage> {
418419
require: true,
419420
min: 18,
420421
),
422+
FormBuilderInput.textField(
423+
type: FormBuilderInput.TYPE_MULTILINE_TEXT,
424+
attribute: "story",
425+
label: "Story",
426+
value: "John Doe",
427+
require: false,
428+
min: 25,
429+
maxLines: 10,
430+
),
421431
FormBuilderInput.textField(
422432
type: FormBuilderInput.TYPE_EMAIL,
423433
attribute: "email",

lib/src/form_builder.dart

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,12 @@ class FormBuilderState extends State<FormBuilder> {
132132
hintText: formControl.hint,
133133
helperText: formControl.hint,
134134
),
135+
autovalidate: formControl.autovalidate,
135136
initialValue:
136137
formControl.value != null ? "${formControl.value}" : '',
137138
maxLines:
138139
formControl.type == FormBuilderInput.TYPE_MULTILINE_TEXT
139-
? 5
140+
? formControl.maxLines
140141
: 1,
141142
keyboardType: keyboardType,
142143
obscureText:
@@ -308,29 +309,26 @@ class FormBuilderState extends State<FormBuilder> {
308309
},
309310
onSaved: (val) => value[formControl.attribute] = val,
310311
getImmediateSuggestions:
311-
formControl.getImmediateSuggestions ?? false,
312+
formControl.getImmediateSuggestions,
312313
errorBuilder: formControl.errorBuilder,
313314
noItemsFoundBuilder: formControl.noItemsFoundBuilder,
314315
loadingBuilder: formControl.loadingBuilder,
315-
debounceDuration: formControl.debounceDuration ??
316-
const Duration(milliseconds: 300),
316+
debounceDuration: formControl.debounceDuration,
317317
suggestionsBoxDecoration:
318-
formControl.suggestionsBoxDecoration ??
319-
const SuggestionsBoxDecoration(),
318+
formControl.suggestionsBoxDecoration,
320319
suggestionsBoxVerticalOffset:
321-
formControl.suggestionsBoxVerticalOffset ?? 5.0,
320+
formControl.suggestionsBoxVerticalOffset,
322321
// transitionBuilder: formControl.transitionBuilder,
323-
animationDuration: formControl.animationDuration ??
324-
const Duration(milliseconds: 500),
325-
animationStart: formControl.animationStart ?? 0.25,
326-
direction: formControl.direction ?? AxisDirection.down,
327-
hideOnLoading: formControl.hideOnLoading ?? false,
328-
hideOnEmpty: formControl.hideOnEmpty ?? false,
329-
hideOnError: formControl.hideOnError ?? false,
322+
animationDuration: formControl.animationDuration,
323+
animationStart: formControl.animationStart,
324+
direction: formControl.direction,
325+
hideOnLoading: formControl.hideOnLoading,
326+
hideOnEmpty: formControl.hideOnEmpty,
327+
hideOnError: formControl.hideOnError,
330328
hideSuggestionsOnKeyboardHide:
331-
formControl.hideSuggestionsOnKeyboardHide ?? true,
329+
formControl.hideSuggestionsOnKeyboardHide,
332330
keepSuggestionsOnLoading:
333-
formControl.keepSuggestionsOnLoading ?? true,
331+
formControl.keepSuggestionsOnLoading,
334332
);
335333
break;
336334

lib/src/form_builder_input.dart

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ class FormBuilderInput {
5454
ItemBuilder itemBuilder;
5555
ChipsBuilder suggestionBuilder;
5656
ChipsBuilder chipBuilder;
57+
int maxLines;
58+
bool autovalidate;
5759

5860
//Inputs for typeahead
5961
bool getImmediateSuggestions;
@@ -84,7 +86,8 @@ class FormBuilderInput {
8486
this.validator,
8587
this.min,
8688
this.max,
87-
//TODO: Include maxLines for multiline text
89+
this.maxLines = 5,
90+
this.autovalidate = false,
8891
}) : assert(min == null || min is int),
8992
assert(max == null || max is int);
9093

@@ -113,22 +116,22 @@ class FormBuilderInput {
113116
this.value,
114117
this.require = false,
115118
this.validator,
116-
this.getImmediateSuggestions,
119+
this.getImmediateSuggestions = false,
117120
this.errorBuilder,
118121
this.noItemsFoundBuilder,
119122
this.loadingBuilder,
120-
this.debounceDuration,
121-
this.suggestionsBoxDecoration,
122-
this.suggestionsBoxVerticalOffset,
123+
this.debounceDuration = const Duration(milliseconds: 300),
124+
this.suggestionsBoxDecoration = const SuggestionsBoxDecoration(),
125+
this.suggestionsBoxVerticalOffset = 5.0,
123126
this.transitionBuilder,
124-
this.animationDuration,
125-
this.animationStart,
126-
this.direction,
127-
this.hideOnLoading,
128-
this.hideOnEmpty,
129-
this.hideOnError,
130-
this.hideSuggestionsOnKeyboardHide,
131-
this.keepSuggestionsOnLoading,
127+
this.animationDuration = const Duration(milliseconds: 500),
128+
this.animationStart = 0.25,
129+
this.direction = AxisDirection.down,
130+
this.hideOnLoading = false,
131+
this.hideOnEmpty = false,
132+
this.hideOnError = false,
133+
this.hideSuggestionsOnKeyboardHide = true,
134+
this.keepSuggestionsOnLoading = true,
132135
}) {
133136
type = FormBuilderInput.TYPE_TYPE_AHEAD;
134137
}

0 commit comments

Comments
 (0)