Skip to content

Commit

Permalink
Flutter v1.20 improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
danvick committed Aug 8, 2020
1 parent 8cd2137 commit 72e8828
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 49 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
## [4.0.0-alpha.10] - 05-Aug-2020
## [4.0.0-beta.1] - 09-Aug-2020
* Flutter v1.20 improvements
* Fix bug in `FormBuilderValidators.numeric` if valueCandidate is `null`
* Renamed `pattern` validator to `match`.
* Rename `requireTrue` validator to `equal` to allow equality check with other types. Closes #397
*
* Fix bug in parsing phone number from `FormBuilderPhoneField.initialValue`

## [4.0.0-alpha.9] - 05-Aug-2020
* Improved programmatically changing field values. Multiple fields can be updated once
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -442,19 +442,19 @@ max, minLength, maxLength, IP, credit card etc. with default `errorText` in Engl
ability to include you own error message that will display whenever validation fails.

Available built-in validators include:
* `FormBuilderValidators.required()` - requires the field have a non-empty value.
* `FormBuilderValidators.numeric()` - requires the field's value to be a valid number.
* `FormBuilderValidators.min()` - requires the field's value to be greater than or equal to the provided number.
* `FormBuilderValidators.creditCard()` - requires the field's value to be a valid credit card number.
* `FormBuilderValidators.date()` - requires the field's value to be a valid date string.
* `FormBuilderValidators.email()` - requires the field's value to be a valid email address.
* `FormBuilderValidators.equal()` - requires the field's value be equal to provided object.
* `FormBuilderValidators.IP()` - requires the field's value to be a valid IP address.
* `FormBuilderValidators.match()` - requires the field's value to match the provided regex pattern.
* `FormBuilderValidators.max()` - requires the field's value to be less than or equal to the provided number.
* `FormBuilderValidators.minLength()` - requires the length of the field's value to be greater than or equal to the provided minimum length.
* `FormBuilderValidators.maxLength()` - requires the length of the field's value to be less than or equal to the provided maximum length.
* `FormBuilderValidators.pattern()` - requires the field's value to match the provided regex pattern.
* `FormBuilderValidators.email()` - requires the field's value to be a valid email address.
* `FormBuilderValidators.min()` - requires the field's value to be greater than or equal to the provided number.
* `FormBuilderValidators.minLength()` - requires the length of the field's value to be greater than or equal to the provided minimum length.
* `FormBuilderValidators.numeric()` - requires the field's value to be a valid number.
* `FormBuilderValidators.required()` - requires the field have a non-empty value.
* ``FormBuilderValidators.url()`` - requires the field's value to be a valid url.
* `FormBuilderValidators.IP()` - requires the field's value to be a valid IP address.
* `FormBuilderValidators.creditCard()` - requires the field's value to be a valid credit card number.
* `FormBuilderValidators.date()` - requires the field's value to be a valid date string.
* `FormBuilderValidators.requiredTrue()` - requires the field's value be true.

### Using multiple validators
`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.
Expand Down
11 changes: 11 additions & 0 deletions lib/src/fields/form_builder_checkbox.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';

Expand All @@ -10,6 +11,9 @@ class FormBuilderCheckbox extends FormBuilderField<bool> {
final Color checkColor;
final ListTileControlAffinity controlAffinity;
final EdgeInsets contentPadding;
final bool autofocus;
final bool tristate;
final bool selected;

FormBuilderCheckbox({
//From Super
Expand All @@ -33,6 +37,9 @@ class FormBuilderCheckbox extends FormBuilderField<bool> {
this.secondary,
this.controlAffinity = ListTileControlAffinity.leading,
this.contentPadding = const EdgeInsets.all(0.0),
this.autofocus = false,
this.tristate = false,
this.selected = false,
}) : super(
key: key,
initialValue: initialValue,
Expand Down Expand Up @@ -70,6 +77,10 @@ class FormBuilderCheckbox extends FormBuilderField<bool> {
activeColor: activeColor,
secondary: secondary,
controlAffinity: controlAffinity,
autofocus: autofocus,
tristate: tristate,
contentPadding: contentPadding,
selected: selected,
),
);
},
Expand Down
40 changes: 29 additions & 11 deletions lib/src/fields/form_builder_date_time_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class FormBuilderDateTimePicker extends FormBuilderField {
/// The latest choosable date. Defaults to 2100.
final DateTime lastDate;

final DateTime currentDate;

/// The initial time prefilled in the picker dialog when it is shown. Defaults
/// to noon. Explicitly set this to `null` to use the current time.
final TimeOfDay initialTime;
Expand Down Expand Up @@ -137,6 +139,10 @@ class FormBuilderDateTimePicker extends FormBuilderField {
final RouteSettings routeSettings;

final PickerType pickerType;
final DateChangedCallback onConfirm;
final DateCancelledCallback onCancel;
final DatePickerTheme theme;
final TimePickerEntryMode timePickerInitialEntryMode;

FormBuilderDateTimePicker({
Key key,
Expand Down Expand Up @@ -207,6 +213,11 @@ class FormBuilderDateTimePicker extends FormBuilderField {
this.helpText,
this.initialEntryMode = DatePickerEntryMode.calendar,
this.routeSettings,
this.currentDate,
this.onConfirm,
this.onCancel,
this.theme,
this.timePickerInitialEntryMode = TimePickerEntryMode.dial,
}) : super(
key: key,
initialValue: initialValue,
Expand Down Expand Up @@ -339,7 +350,7 @@ class _FormBuilderDateTimePickerState extends FormBuilderFieldState {
}
break;
default:
throw 'Unexcepted input type ${widget.inputType}';
throw 'Unexpected input type ${widget.inputType}';
break;
}
newValue = newValue ?? currentValue;
Expand All @@ -353,16 +364,18 @@ class _FormBuilderDateTimePickerState extends FormBuilderFieldState {
return widget.datePicker(context);
} else {
if (widget.pickerType == PickerType.cupertino) {
return DatePicker.showDatePicker(
context,
showTitleActions: true,
minTime: widget.firstDate,
maxTime: widget.lastDate,
currentTime: currentValue,
locale: enumValueFromString(
(widget.locale ?? Localizations.localeOf(context))?.languageCode,
LocaleType.values),
);
return DatePicker.showDatePicker(context,
showTitleActions: true,
minTime: widget.firstDate,
maxTime: widget.lastDate,
currentTime: currentValue,
locale: enumValueFromString(
(widget.locale ?? Localizations.localeOf(context))
?.languageCode,
LocaleType.values),
theme: widget.theme,
onCancel: widget.onCancel,
onConfirm: widget.onConfirm);
}
return showDatePicker(
context: context,
Expand Down Expand Up @@ -392,6 +405,7 @@ class _FormBuilderDateTimePickerState extends FormBuilderFieldState {
helpText: widget.helpText,
initialEntryMode: widget.initialEntryMode,
routeSettings: widget.routeSettings,
currentDate: widget.currentDate,
);
}
}
Expand Down Expand Up @@ -446,6 +460,10 @@ class _FormBuilderDateTimePickerState extends FormBuilderFieldState {
},
useRootNavigator: widget.useRootNavigator,
routeSettings: widget.routeSettings,
initialEntryMode: widget.timePickerInitialEntryMode,
helpText: widget.helpText,
confirmText: widget.confirmText,
cancelText: widget.cancelText,
).then(
(result) {
return result ??
Expand Down
17 changes: 9 additions & 8 deletions lib/src/fields/form_builder_segmented_control.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class FormBuilderSegmentedControl<T> extends FormBuilderField<T> {
decoration: decoration,
builder: (FormFieldState field) {
final _FormBuilderSegmentedControlState state = field;
final theme = Theme.of(state.context);

return InputDecorator(
decoration: decoration.copyWith(
Expand All @@ -55,16 +56,16 @@ class FormBuilderSegmentedControl<T> extends FormBuilderField<T> {
),
child: Padding(
padding: EdgeInsets.only(top: 10.0),
child: CupertinoSegmentedControl(
child: CupertinoSegmentedControl<T>(
borderColor: state.readOnly
? Theme.of(state.context).disabledColor
: borderColor ?? Theme.of(state.context).primaryColor,
? theme.disabledColor
: borderColor ?? theme.primaryColor,
selectedColor: state.readOnly
? Theme.of(state.context).disabledColor
: selectedColor ?? Theme.of(state.context).primaryColor,
? theme.disabledColor
: selectedColor ?? theme.primaryColor,
pressedColor: state.readOnly
? Theme.of(state.context).disabledColor
: pressedColor ?? Theme.of(state.context).primaryColor,
? theme.disabledColor
: pressedColor ?? theme.primaryColor,
groupValue: state.value,
children: {
for (var option in options)
Expand All @@ -75,7 +76,7 @@ class FormBuilderSegmentedControl<T> extends FormBuilderField<T> {
},
padding: padding,
unselectedColor: unselectedColor,
onValueChanged: (dynamic value) {
onValueChanged: (T value) {
state.requestFocus();
if (state.readOnly) {
field.reset();
Expand Down
26 changes: 20 additions & 6 deletions lib/src/fields/form_builder_slider.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:intl/intl.dart';
Expand All @@ -20,6 +21,8 @@ class FormBuilderSlider extends FormBuilderField {
final TextStyle minTextStyle;
final TextStyle textStyle;
final TextStyle maxTextStyle;
final bool autofocus;
final MouseCursor mouseCursor;

FormBuilderSlider({
Key key,
Expand Down Expand Up @@ -50,6 +53,8 @@ class FormBuilderSlider extends FormBuilderField {
this.minTextStyle,
this.textStyle,
this.maxTextStyle,
this.autofocus = false,
this.mouseCursor,
}) : super(
key: key,
initialValue: initialValue,
Expand Down Expand Up @@ -93,23 +98,32 @@ class FormBuilderSlider extends FormBuilderField {
state.requestFocus();
field.didChange(value);
},
autofocus: autofocus,
mouseCursor: mouseCursor,
focusNode: focusNode,
),
Row(
children: <Widget>[
if (displayValues != DisplayValues.none &&
displayValues != DisplayValues.current)
Text('${_numberFormat.format(min)}',
style: minTextStyle ?? textStyle),
Text(
'${_numberFormat.format(min)}',
style: minTextStyle ?? textStyle,
),
Spacer(),
if (displayValues != DisplayValues.none &&
displayValues != DisplayValues.minMax)
Text('${_numberFormat.format(field.value)}',
style: textStyle),
Text(
'${_numberFormat.format(field.value)}',
style: textStyle,
),
Spacer(),
if (displayValues != DisplayValues.none &&
displayValues != DisplayValues.current)
Text('${_numberFormat.format(max)}',
style: maxTextStyle ?? textStyle),
Text(
'${_numberFormat.format(max)}',
style: maxTextStyle ?? textStyle,
),
],
),
],
Expand Down
7 changes: 7 additions & 0 deletions lib/src/fields/form_builder_switch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class FormBuilderSwitch extends FormBuilderField {

/// {@macro flutter.cupertino.switch.dragStartBehavior}
final ListTileControlAffinity controlAffinity;
final bool autofocus;
final bool selected;

FormBuilderSwitch({
Key key,
Expand Down Expand Up @@ -76,6 +78,8 @@ class FormBuilderSwitch extends FormBuilderField {
this.secondary,
this.controlAffinity = ListTileControlAffinity.trailing,
this.contentPadding = const EdgeInsets.all(0.0),
this.autofocus = false,
this.selected = false,
}) : super(
key: key,
initialValue: initialValue,
Expand Down Expand Up @@ -117,6 +121,9 @@ class FormBuilderSwitch extends FormBuilderField {
inactiveTrackColor: inactiveTrackColor,
secondary: secondary,
subtitle: subtitle,
autofocus: autofocus,
selected: selected,
controlAffinity: controlAffinity,
),
);
},
Expand Down
10 changes: 10 additions & 0 deletions lib/src/fields/form_builder_text_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:ui' as ui show BoxHeightStyle, BoxWidthStyle;

import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';
Expand Down Expand Up @@ -46,6 +47,9 @@ class FormBuilderTextField extends FormBuilderField {
final SmartDashesType smartDashesType;
final SmartQuotesType smartQuotesType;
final ToolbarOptions toolbarOptions;
final Iterable<String> autofillHints;
final String obscuringCharacter;
final MouseCursor mouseCursor;

FormBuilderTextField({
Key key,
Expand Down Expand Up @@ -100,6 +104,9 @@ class FormBuilderTextField extends FormBuilderField {
this.smartQuotesType,
this.toolbarOptions,
this.selectionHeightStyle = ui.BoxHeightStyle.tight,
this.autofillHints,
this.obscuringCharacter = '•',
this.mouseCursor,
}) : assert(initialValue == null || controller == null),
assert(textAlign != null),
assert(autofocus != null),
Expand Down Expand Up @@ -192,6 +199,9 @@ class FormBuilderTextField extends FormBuilderField {
smartDashesType: smartDashesType,
smartQuotesType: smartQuotesType,
toolbarOptions: toolbarOptions,
mouseCursor: mouseCursor,
obscuringCharacter: obscuringCharacter,
autofillHints: autofillHints,
);
},
);
Expand Down
10 changes: 4 additions & 6 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ packages:
name: flutter_chips_input
url: "https://pub.dartlang.org"
source: hosted
version: "1.9.0"
version: "1.9.1"
flutter_colorpicker:
dependency: "direct main"
description:
Expand All @@ -177,11 +177,9 @@ packages:
flutter_datetime_picker:
dependency: "direct main"
description:
path: "."
ref: patch-1
resolved-ref: "974f3d805dec941435fe62289e1948ba7d979f05"
url: "https://github.com/ditheshthegreat/flutter_datetime_picker"
source: git
name: flutter_datetime_picker
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.8"
flutter_keyboard_visibility:
dependency: transitive
Expand Down
8 changes: 2 additions & 6 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_form_builder
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.
version: 4.0.0-alpha.9
version: 4.0.0-beta.1
homepage: https://github.com/danvick/flutter_form_builder

environment:
Expand All @@ -27,11 +27,7 @@ dependencies:
rating_bar: ^0.2.0
signature: ^3.2.0
validators: ^2.0.1
# flutter_datetime_picker: ^1.3.8
flutter_datetime_picker:
git:
url: https://github.com/ditheshthegreat/flutter_datetime_picker
ref: patch-1
flutter_datetime_picker: ^1.3.8
searchable_dropdown: ^1.1.3

dev_dependencies:
Expand Down

0 comments on commit 72e8828

Please sign in to comment.