Skip to content

Commit 32b6179

Browse files
committed
Setting of initial value for ChipsInput done
1 parent 5a0d088 commit 32b6179

File tree

5 files changed

+54
-85
lines changed

5 files changed

+54
-85
lines changed

.idea/workspace.xml

Lines changed: 37 additions & 79 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ FormBuilder(
189189
* Add more `FormBuilderInput` types
190190

191191
## KNOWN ISSUES - HELP NEEDED (Send help ;-P)
192-
* Proper validation for URL
192+
* Proper validation for URL [doesn't work without http(s)]
193193
* Resetting the form doesn't clear all `FormField`s
194+
* Overlay for ChipsInput doesn't move when input height changes i.e. when chips wrap
195+
* For some reason Overlay for ChipsInput floats above AppBar when scrolling
196+
* DatePicker and TimePicker Textfields don't get focus when selecting
194197

example/lib/main.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,15 @@ class MyHomePage extends StatelessWidget {
7070
child: FormBuilder(
7171
context,
7272
autovalidate: true,
73-
// showResetButton: true,
73+
showResetButton: true,
7474
// resetButtonContent: Text("Clear Form"),
7575
controls: [
7676
FormBuilderInput.chipsInput(
7777
label: 'Chips',
7878
attribute: 'chips_test',
7979
require: true,
80+
value: [AppProfile('Stock Man', '[email protected]',
81+
'https://d2gg9evh47fn9z.cloudfront.net/800px_COLOURBOX4057996.jpg')],
8082
suggestionsCallback: (String query) {
8183
if (query.length != 0) {
8284
return mockResults.where((profile) {

lib/src/chips_input.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ typedef ChipsBuilder<T> = Widget Function(
1010
class ChipsInput<T> extends StatefulWidget {
1111
const ChipsInput({
1212
Key key,
13+
this.initialValue = const [],
1314
this.decoration = const InputDecoration(),
1415
@required this.chipBuilder,
1516
@required this.suggestionBuilder,
@@ -24,6 +25,7 @@ class ChipsInput<T> extends StatefulWidget {
2425
final ValueChanged<T> onChipTapped;
2526
final ChipsBuilder<T> chipBuilder;
2627
final ChipsBuilder<T> suggestionBuilder;
28+
final List<T> initialValue;
2729

2830
@override
2931
ChipsInputState<T> createState() => ChipsInputState<T>();
@@ -51,6 +53,10 @@ class ChipsInputState<T> extends State<ChipsInput<T>>
5153
@override
5254
void initState() {
5355
super.initState();
56+
_chips.addAll(widget.initialValue);
57+
/*widget.initialValue.forEach((data){
58+
selectSuggestion(data);
59+
});*/
5460
this._focusNode = FocusNode();
5561
this._suggestionsBoxController = _SuggestionsBoxController(context);
5662
this._suggestionsStreamController = StreamController<List<T>>.broadcast();
@@ -210,7 +216,7 @@ class ChipsInputState<T> extends State<ChipsInput<T>>
210216
child: InputDecorator(
211217
decoration: widget.decoration,
212218
isFocused: _focusNode.hasFocus,
213-
isEmpty: _value.text.length == 0,
219+
isEmpty: _value.text.length == 0 && _chips.length == 0,
214220
child: Wrap(
215221
children: chipsChildren,
216222
spacing: 4.0,

lib/src/form_builder.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class _FormBuilderState extends State<FormBuilder> {
208208
value: option.value,
209209
);
210210
}).toList(),
211-
value: formControl.value,
211+
value: field.value,
212212
onChanged: (value) {
213213
setState(() {
214214
formControls[count].value = value;
@@ -255,7 +255,7 @@ class _FormBuilderState extends State<FormBuilder> {
255255
formControls[count].options[i].value),
256256
trailing: Radio<dynamic>(
257257
value: formControls[count].options[i].value,
258-
groupValue: formControls[count].value,
258+
groupValue: field.value,
259259
onChanged: (dynamic value) {
260260
setState(() {
261261
formControls[count].value = value;
@@ -638,7 +638,7 @@ class _FormBuilderState extends State<FormBuilder> {
638638
},
639639
builder: (FormFieldState<dynamic> field) {
640640
return ChipsInput(
641-
// key: GlobalKey<ChipsInputState>(),
641+
initialValue: field.value,
642642
decoration: InputDecoration(
643643
// prefixIcon: Icon(Icons.search),
644644
hintText: formControl.hint,

0 commit comments

Comments
 (0)