Skip to content

Commit 72e8828

Browse files
committed
Flutter v1.20 improvements
1 parent 8cd2137 commit 72e8828

10 files changed

+106
-49
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
## [4.0.0-alpha.10] - 05-Aug-2020
1+
## [4.0.0-beta.1] - 09-Aug-2020
2+
* Flutter v1.20 improvements
3+
* Fix bug in `FormBuilderValidators.numeric` if valueCandidate is `null`
24
* Renamed `pattern` validator to `match`.
35
* Rename `requireTrue` validator to `equal` to allow equality check with other types. Closes #397
4-
*
6+
* Fix bug in parsing phone number from `FormBuilderPhoneField.initialValue`
57

68
## [4.0.0-alpha.9] - 05-Aug-2020
79
* Improved programmatically changing field values. Multiple fields can be updated once

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -442,19 +442,19 @@ max, minLength, maxLength, IP, credit card etc. with default `errorText` in Engl
442442
ability to include you own error message that will display whenever validation fails.
443443

444444
Available built-in validators include:
445-
* `FormBuilderValidators.required()` - requires the field have a non-empty value.
446-
* `FormBuilderValidators.numeric()` - requires the field's value to be a valid number.
447-
* `FormBuilderValidators.min()` - requires the field's value to be greater than or equal to the provided number.
445+
* `FormBuilderValidators.creditCard()` - requires the field's value to be a valid credit card number.
446+
* `FormBuilderValidators.date()` - requires the field's value to be a valid date string.
447+
* `FormBuilderValidators.email()` - requires the field's value to be a valid email address.
448+
* `FormBuilderValidators.equal()` - requires the field's value be equal to provided object.
449+
* `FormBuilderValidators.IP()` - requires the field's value to be a valid IP address.
450+
* `FormBuilderValidators.match()` - requires the field's value to match the provided regex pattern.
448451
* `FormBuilderValidators.max()` - requires the field's value to be less than or equal to the provided number.
449-
* `FormBuilderValidators.minLength()` - requires the length of the field's value to be greater than or equal to the provided minimum length.
450452
* `FormBuilderValidators.maxLength()` - requires the length of the field's value to be less than or equal to the provided maximum length.
451-
* `FormBuilderValidators.pattern()` - requires the field's value to match the provided regex pattern.
452-
* `FormBuilderValidators.email()` - requires the field's value to be a valid email address.
453+
* `FormBuilderValidators.min()` - requires the field's value to be greater than or equal to the provided number.
454+
* `FormBuilderValidators.minLength()` - requires the length of the field's value to be greater than or equal to the provided minimum length.
455+
* `FormBuilderValidators.numeric()` - requires the field's value to be a valid number.
456+
* `FormBuilderValidators.required()` - requires the field have a non-empty value.
453457
* ``FormBuilderValidators.url()`` - requires the field's value to be a valid url.
454-
* `FormBuilderValidators.IP()` - requires the field's value to be a valid IP address.
455-
* `FormBuilderValidators.creditCard()` - requires the field's value to be a valid credit card number.
456-
* `FormBuilderValidators.date()` - requires the field's value to be a valid date string.
457-
* `FormBuilderValidators.requiredTrue()` - requires the field's value be true.
458458

459459
### Using multiple validators
460460
`FormBuilderValidators` class comes with a very useful static function named `compose()` which takes in any number of `FormFieldValidator` functions. On validation each validator is run and if any returns a non-null value (i.e. a String), validation fails and the `errorText` for the field is set as the returned string.

lib/src/fields/form_builder_checkbox.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:flutter/material.dart';
2+
import 'package:flutter/rendering.dart';
23
import 'package:flutter/widgets.dart';
34
import 'package:flutter_form_builder/flutter_form_builder.dart';
45

@@ -10,6 +11,9 @@ class FormBuilderCheckbox extends FormBuilderField<bool> {
1011
final Color checkColor;
1112
final ListTileControlAffinity controlAffinity;
1213
final EdgeInsets contentPadding;
14+
final bool autofocus;
15+
final bool tristate;
16+
final bool selected;
1317

1418
FormBuilderCheckbox({
1519
//From Super
@@ -33,6 +37,9 @@ class FormBuilderCheckbox extends FormBuilderField<bool> {
3337
this.secondary,
3438
this.controlAffinity = ListTileControlAffinity.leading,
3539
this.contentPadding = const EdgeInsets.all(0.0),
40+
this.autofocus = false,
41+
this.tristate = false,
42+
this.selected = false,
3643
}) : super(
3744
key: key,
3845
initialValue: initialValue,
@@ -70,6 +77,10 @@ class FormBuilderCheckbox extends FormBuilderField<bool> {
7077
activeColor: activeColor,
7178
secondary: secondary,
7279
controlAffinity: controlAffinity,
80+
autofocus: autofocus,
81+
tristate: tristate,
82+
contentPadding: contentPadding,
83+
selected: selected,
7384
),
7485
);
7586
},

lib/src/fields/form_builder_date_time_picker.dart

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class FormBuilderDateTimePicker extends FormBuilderField {
3636
/// The latest choosable date. Defaults to 2100.
3737
final DateTime lastDate;
3838

39+
final DateTime currentDate;
40+
3941
/// The initial time prefilled in the picker dialog when it is shown. Defaults
4042
/// to noon. Explicitly set this to `null` to use the current time.
4143
final TimeOfDay initialTime;
@@ -137,6 +139,10 @@ class FormBuilderDateTimePicker extends FormBuilderField {
137139
final RouteSettings routeSettings;
138140

139141
final PickerType pickerType;
142+
final DateChangedCallback onConfirm;
143+
final DateCancelledCallback onCancel;
144+
final DatePickerTheme theme;
145+
final TimePickerEntryMode timePickerInitialEntryMode;
140146

141147
FormBuilderDateTimePicker({
142148
Key key,
@@ -207,6 +213,11 @@ class FormBuilderDateTimePicker extends FormBuilderField {
207213
this.helpText,
208214
this.initialEntryMode = DatePickerEntryMode.calendar,
209215
this.routeSettings,
216+
this.currentDate,
217+
this.onConfirm,
218+
this.onCancel,
219+
this.theme,
220+
this.timePickerInitialEntryMode = TimePickerEntryMode.dial,
210221
}) : super(
211222
key: key,
212223
initialValue: initialValue,
@@ -339,7 +350,7 @@ class _FormBuilderDateTimePickerState extends FormBuilderFieldState {
339350
}
340351
break;
341352
default:
342-
throw 'Unexcepted input type ${widget.inputType}';
353+
throw 'Unexpected input type ${widget.inputType}';
343354
break;
344355
}
345356
newValue = newValue ?? currentValue;
@@ -353,16 +364,18 @@ class _FormBuilderDateTimePickerState extends FormBuilderFieldState {
353364
return widget.datePicker(context);
354365
} else {
355366
if (widget.pickerType == PickerType.cupertino) {
356-
return DatePicker.showDatePicker(
357-
context,
358-
showTitleActions: true,
359-
minTime: widget.firstDate,
360-
maxTime: widget.lastDate,
361-
currentTime: currentValue,
362-
locale: enumValueFromString(
363-
(widget.locale ?? Localizations.localeOf(context))?.languageCode,
364-
LocaleType.values),
365-
);
367+
return DatePicker.showDatePicker(context,
368+
showTitleActions: true,
369+
minTime: widget.firstDate,
370+
maxTime: widget.lastDate,
371+
currentTime: currentValue,
372+
locale: enumValueFromString(
373+
(widget.locale ?? Localizations.localeOf(context))
374+
?.languageCode,
375+
LocaleType.values),
376+
theme: widget.theme,
377+
onCancel: widget.onCancel,
378+
onConfirm: widget.onConfirm);
366379
}
367380
return showDatePicker(
368381
context: context,
@@ -392,6 +405,7 @@ class _FormBuilderDateTimePickerState extends FormBuilderFieldState {
392405
helpText: widget.helpText,
393406
initialEntryMode: widget.initialEntryMode,
394407
routeSettings: widget.routeSettings,
408+
currentDate: widget.currentDate,
395409
);
396410
}
397411
}
@@ -446,6 +460,10 @@ class _FormBuilderDateTimePickerState extends FormBuilderFieldState {
446460
},
447461
useRootNavigator: widget.useRootNavigator,
448462
routeSettings: widget.routeSettings,
463+
initialEntryMode: widget.timePickerInitialEntryMode,
464+
helpText: widget.helpText,
465+
confirmText: widget.confirmText,
466+
cancelText: widget.cancelText,
449467
).then(
450468
(result) {
451469
return result ??

lib/src/fields/form_builder_segmented_control.dart

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class FormBuilderSegmentedControl<T> extends FormBuilderField<T> {
4747
decoration: decoration,
4848
builder: (FormFieldState field) {
4949
final _FormBuilderSegmentedControlState state = field;
50+
final theme = Theme.of(state.context);
5051

5152
return InputDecorator(
5253
decoration: decoration.copyWith(
@@ -55,16 +56,16 @@ class FormBuilderSegmentedControl<T> extends FormBuilderField<T> {
5556
),
5657
child: Padding(
5758
padding: EdgeInsets.only(top: 10.0),
58-
child: CupertinoSegmentedControl(
59+
child: CupertinoSegmentedControl<T>(
5960
borderColor: state.readOnly
60-
? Theme.of(state.context).disabledColor
61-
: borderColor ?? Theme.of(state.context).primaryColor,
61+
? theme.disabledColor
62+
: borderColor ?? theme.primaryColor,
6263
selectedColor: state.readOnly
63-
? Theme.of(state.context).disabledColor
64-
: selectedColor ?? Theme.of(state.context).primaryColor,
64+
? theme.disabledColor
65+
: selectedColor ?? theme.primaryColor,
6566
pressedColor: state.readOnly
66-
? Theme.of(state.context).disabledColor
67-
: pressedColor ?? Theme.of(state.context).primaryColor,
67+
? theme.disabledColor
68+
: pressedColor ?? theme.primaryColor,
6869
groupValue: state.value,
6970
children: {
7071
for (var option in options)
@@ -75,7 +76,7 @@ class FormBuilderSegmentedControl<T> extends FormBuilderField<T> {
7576
},
7677
padding: padding,
7778
unselectedColor: unselectedColor,
78-
onValueChanged: (dynamic value) {
79+
onValueChanged: (T value) {
7980
state.requestFocus();
8081
if (state.readOnly) {
8182
field.reset();

lib/src/fields/form_builder_slider.dart

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:flutter/material.dart';
2+
import 'package:flutter/rendering.dart';
23
import 'package:flutter/widgets.dart';
34
import 'package:flutter_form_builder/flutter_form_builder.dart';
45
import 'package:intl/intl.dart';
@@ -20,6 +21,8 @@ class FormBuilderSlider extends FormBuilderField {
2021
final TextStyle minTextStyle;
2122
final TextStyle textStyle;
2223
final TextStyle maxTextStyle;
24+
final bool autofocus;
25+
final MouseCursor mouseCursor;
2326

2427
FormBuilderSlider({
2528
Key key,
@@ -50,6 +53,8 @@ class FormBuilderSlider extends FormBuilderField {
5053
this.minTextStyle,
5154
this.textStyle,
5255
this.maxTextStyle,
56+
this.autofocus = false,
57+
this.mouseCursor,
5358
}) : super(
5459
key: key,
5560
initialValue: initialValue,
@@ -93,23 +98,32 @@ class FormBuilderSlider extends FormBuilderField {
9398
state.requestFocus();
9499
field.didChange(value);
95100
},
101+
autofocus: autofocus,
102+
mouseCursor: mouseCursor,
103+
focusNode: focusNode,
96104
),
97105
Row(
98106
children: <Widget>[
99107
if (displayValues != DisplayValues.none &&
100108
displayValues != DisplayValues.current)
101-
Text('${_numberFormat.format(min)}',
102-
style: minTextStyle ?? textStyle),
109+
Text(
110+
'${_numberFormat.format(min)}',
111+
style: minTextStyle ?? textStyle,
112+
),
103113
Spacer(),
104114
if (displayValues != DisplayValues.none &&
105115
displayValues != DisplayValues.minMax)
106-
Text('${_numberFormat.format(field.value)}',
107-
style: textStyle),
116+
Text(
117+
'${_numberFormat.format(field.value)}',
118+
style: textStyle,
119+
),
108120
Spacer(),
109121
if (displayValues != DisplayValues.none &&
110122
displayValues != DisplayValues.current)
111-
Text('${_numberFormat.format(max)}',
112-
style: maxTextStyle ?? textStyle),
123+
Text(
124+
'${_numberFormat.format(max)}',
125+
style: maxTextStyle ?? textStyle,
126+
),
113127
],
114128
),
115129
],

lib/src/fields/form_builder_switch.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class FormBuilderSwitch extends FormBuilderField {
4949

5050
/// {@macro flutter.cupertino.switch.dragStartBehavior}
5151
final ListTileControlAffinity controlAffinity;
52+
final bool autofocus;
53+
final bool selected;
5254

5355
FormBuilderSwitch({
5456
Key key,
@@ -76,6 +78,8 @@ class FormBuilderSwitch extends FormBuilderField {
7678
this.secondary,
7779
this.controlAffinity = ListTileControlAffinity.trailing,
7880
this.contentPadding = const EdgeInsets.all(0.0),
81+
this.autofocus = false,
82+
this.selected = false,
7983
}) : super(
8084
key: key,
8185
initialValue: initialValue,
@@ -117,6 +121,9 @@ class FormBuilderSwitch extends FormBuilderField {
117121
inactiveTrackColor: inactiveTrackColor,
118122
secondary: secondary,
119123
subtitle: subtitle,
124+
autofocus: autofocus,
125+
selected: selected,
126+
controlAffinity: controlAffinity,
120127
),
121128
);
122129
},

lib/src/fields/form_builder_text_field.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'dart:ui' as ui show BoxHeightStyle, BoxWidthStyle;
33

44
import 'package:flutter/gestures.dart';
55
import 'package:flutter/material.dart';
6+
import 'package:flutter/rendering.dart';
67
import 'package:flutter/services.dart';
78
import 'package:flutter/widgets.dart';
89
import 'package:flutter_form_builder/flutter_form_builder.dart';
@@ -46,6 +47,9 @@ class FormBuilderTextField extends FormBuilderField {
4647
final SmartDashesType smartDashesType;
4748
final SmartQuotesType smartQuotesType;
4849
final ToolbarOptions toolbarOptions;
50+
final Iterable<String> autofillHints;
51+
final String obscuringCharacter;
52+
final MouseCursor mouseCursor;
4953

5054
FormBuilderTextField({
5155
Key key,
@@ -100,6 +104,9 @@ class FormBuilderTextField extends FormBuilderField {
100104
this.smartQuotesType,
101105
this.toolbarOptions,
102106
this.selectionHeightStyle = ui.BoxHeightStyle.tight,
107+
this.autofillHints,
108+
this.obscuringCharacter = '•',
109+
this.mouseCursor,
103110
}) : assert(initialValue == null || controller == null),
104111
assert(textAlign != null),
105112
assert(autofocus != null),
@@ -192,6 +199,9 @@ class FormBuilderTextField extends FormBuilderField {
192199
smartDashesType: smartDashesType,
193200
smartQuotesType: smartQuotesType,
194201
toolbarOptions: toolbarOptions,
202+
mouseCursor: mouseCursor,
203+
obscuringCharacter: obscuringCharacter,
204+
autofillHints: autofillHints,
195205
);
196206
},
197207
);

pubspec.lock

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ packages:
166166
name: flutter_chips_input
167167
url: "https://pub.dartlang.org"
168168
source: hosted
169-
version: "1.9.0"
169+
version: "1.9.1"
170170
flutter_colorpicker:
171171
dependency: "direct main"
172172
description:
@@ -177,11 +177,9 @@ packages:
177177
flutter_datetime_picker:
178178
dependency: "direct main"
179179
description:
180-
path: "."
181-
ref: patch-1
182-
resolved-ref: "974f3d805dec941435fe62289e1948ba7d979f05"
183-
url: "https://github.com/ditheshthegreat/flutter_datetime_picker"
184-
source: git
180+
name: flutter_datetime_picker
181+
url: "https://pub.dartlang.org"
182+
source: hosted
185183
version: "1.3.8"
186184
flutter_keyboard_visibility:
187185
dependency: transitive

pubspec.yaml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_form_builder
22
description: Package to build Material Form with fields like TextField, DropDown, Switches etc. with ability to create custom FormFields and composability and reuse validation functions.
3-
version: 4.0.0-alpha.9
3+
version: 4.0.0-beta.1
44
homepage: https://github.com/danvick/flutter_form_builder
55

66
environment:
@@ -27,11 +27,7 @@ dependencies:
2727
rating_bar: ^0.2.0
2828
signature: ^3.2.0
2929
validators: ^2.0.1
30-
# flutter_datetime_picker: ^1.3.8
31-
flutter_datetime_picker:
32-
git:
33-
url: https://github.com/ditheshthegreat/flutter_datetime_picker
34-
ref: patch-1
30+
flutter_datetime_picker: ^1.3.8
3531
searchable_dropdown: ^1.1.3
3632

3733
dev_dependencies:

0 commit comments

Comments
 (0)