Skip to content

Commit 8c976a2

Browse files
committed
Fix issue where form's initialValue would potentially be ignored. Fixes #341
1 parent f993302 commit 8c976a2

File tree

5 files changed

+35
-26
lines changed

5 files changed

+35
-26
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## [3.13.2] - 11-Aug-2020
2+
* Added `defaultImage` attribute to `FormBuilderImagePicker`, acts as placeholder. Courtesy [luwenbin8023](https://github.com/luwenbin8023)
3+
* Fix bug in `FormBuilderCheckboxGroup` where `InputDecoration` isn't enabled. Closes #405
4+
* Fix issue where form's initialValue would potentially be ignored. Fixes #341
5+
16
## [3.13.1] - 08-Aug-2020
27
* Added default value to `timePickerInitialEntryMode` to be consistent with `showTimePicker` API. Closes #403
38
* Ensure `TextEditingController`s aren't unused and are properly disposed.

example/lib/main.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,15 @@ class MyHomePageState extends State<MyHomePage> {
6363
// autovalidate: true,
6464
initialValue: {
6565
'movie_rating': 3,
66+
'filter_chip': ['Test', 'Test 1'],
6667
},
6768
readOnly: false,
6869
child: Column(
6970
children: <Widget>[
7071
FormBuilderFilterChip(
7172
attribute: 'filter_chip',
7273
decoration: const InputDecoration(
73-
labelText: 'Select many options',
74+
labelText: 'Filter Chip',
7475
),
7576
options: [
7677
FormBuilderFieldOption(
@@ -452,7 +453,8 @@ class MyHomePageState extends State<MyHomePage> {
452453
decoration: const InputDecoration(
453454
labelText: 'Images',
454455
),
455-
defaultImage: NetworkImage('https://cohenwoodworking.com/wp-content/uploads/2016/09/image-placeholder-500x500.jpg'),
456+
defaultImage: NetworkImage(
457+
'https://cohenwoodworking.com/wp-content/uploads/2016/09/image-placeholder-500x500.jpg'),
456458
maxImages: 3,
457459
iconColor: Colors.red,
458460
// readOnly: true,

lib/src/fields/form_builder_image_picker.dart

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class _FormBuilderImagePickerState extends State<FormBuilderImagePicker> {
8989
return false;
9090
} else {
9191
return /*_fieldKey.currentState.value != null &&*/ _fieldKey
92-
.currentState.value.length >=
92+
.currentState.value.length >=
9393
widget.maxImages;
9494
}
9595
}
@@ -161,8 +161,8 @@ class _FormBuilderImagePickerState extends State<FormBuilderImagePicker> {
161161
child: kIsWeb
162162
? Image.memory(item, fit: BoxFit.cover)
163163
: item is String
164-
? Image.network(item, fit: BoxFit.cover)
165-
: Image.file(item, fit: BoxFit.cover),
164+
? Image.network(item, fit: BoxFit.cover)
165+
: Image.file(item, fit: BoxFit.cover),
166166
),
167167
if (!_readOnly)
168168
InkWell(
@@ -191,24 +191,26 @@ class _FormBuilderImagePickerState extends State<FormBuilderImagePicker> {
191191
}).toList()),
192192
if (!_readOnly && !_hasMaxImages)
193193
GestureDetector(
194-
child: widget.defaultImage != null?
195-
Image(
196-
width: widget.imageWidth,
197-
height: widget.imageHeight,
198-
image: widget.defaultImage,
199-
):Container(
200-
width: widget.imageWidth,
201-
height: widget.imageHeight,
202-
child: Icon(Icons.camera_enhance,
203-
color: _readOnly
204-
? theme.disabledColor
205-
: widget.iconColor ?? theme.primaryColor
206-
),
207-
color: (_readOnly
208-
? theme.disabledColor
209-
: widget.iconColor ?? theme.primaryColor)
210-
.withAlpha(50),
211-
),
194+
child: widget.defaultImage != null
195+
? Image(
196+
width: widget.imageWidth,
197+
height: widget.imageHeight,
198+
image: widget.defaultImage,
199+
)
200+
: Container(
201+
width: widget.imageWidth,
202+
height: widget.imageHeight,
203+
child: Icon(Icons.camera_enhance,
204+
color: _readOnly
205+
? theme.disabledColor
206+
: widget.iconColor ??
207+
theme.primaryColor),
208+
color: (_readOnly
209+
? theme.disabledColor
210+
: widget.iconColor ??
211+
theme.primaryColor)
212+
.withAlpha(50),
213+
),
212214
onTap: () {
213215
showModalBottomSheet(
214216
context: context,
@@ -218,7 +220,7 @@ class _FormBuilderImagePickerState extends State<FormBuilderImagePicker> {
218220
maxWidth: widget.maxWidth,
219221
imageQuality: widget.imageQuality,
220222
preferredCameraDevice:
221-
widget.preferredCameraDevice,
223+
widget.preferredCameraDevice,
222224
cameraIcon: widget.cameraIcon,
223225
galleryIcon: widget.galleryIcon,
224226
cameraLabel: widget.cameraLabel,

lib/src/fields/form_builder_typeahead.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class _FormBuilderTypeAheadState<T> extends State<FormBuilderTypeAhead<T>> {
105105
: widget.textFieldConfiguration.focusNode;
106106

107107
_initialValue = widget.initialValue ??
108-
_typeAheadController.text ??
108+
widget.controller?.text ??
109109
((_formState?.initialValue?.containsKey(widget.attribute) ?? false)
110110
? _formState.initialValue[widget.attribute]
111111
: null);

pubspec.yaml

Lines changed: 1 addition & 1 deletion
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: 3.13.1
3+
version: 3.13.2
44
homepage: https://github.com/danvick/flutter_form_builder
55

66
environment:

0 commit comments

Comments
 (0)