hiddencaliber / flutter_multiselect

Flutter package for multi-select UI widget
Other
52 stars 37 forks source link

OnSaved not saving the values #26

Closed CarltonBranch closed 3 years ago

CarltonBranch commented 4 years ago

Hi, In terms of functionality everything is working normally. However the value field is always null. The onSaved function doesn't print the value. Even when I copy/paste your example code into my project I get the same behaviour. Everything looks like it's working but the value field is not populated.

Any ideas would by greatly appreciated

This is the example code from the main page. I had to add the colours since they were throwing an error because they can't be null.


MultiSelect(
              enabledBorderColor: Colors.grey,
              errorBorderColor: Colors.grey,
              selectIconColor: Colors.white,
              inputBoxFillColor: Colors.grey[800],
              searchBoxColor: Colors.grey[800],
              cancelButtonTextColor: Colors.white,
              cancelButtonColor: Colors.grey[800],
              buttonBarColor: Colors.grey[800],
              hintTextColor: Colors.white,
              selectedOptionsInfoTextColor: Colors.black,
              checkBoxColor: Colors.white,
              searchBoxFillColor: Colors.black,
              autovalidate: false,
              titleText: "title",
              validator: (value) {
                if (value == null) {
                  return 'Please select one or more option(s)';
                }
                return "";
              },
              errorText: 'Please select one or more option(s)',
              dataSource: [
                {
                  "display": "Australia",
                  "value": 1,
                },
                {
                  "display": "Canada",
                  "value": 2,
                },
                {
                  "display": "India",
                  "value": 3,
                },
                {
                  "display": "United States",
                  "value": 4,
                }
              ],
              textField: 'display',
              valueField: 'value',
              filterable: true,
              required: true,
              value: null,
              onSaved: (value) {
                print('The value is $value');
              }),
hiddencaliber commented 4 years ago

@CarltonBranch Please check the complete example. https://github.com/hiddencaliber/flutter_multiselect/blob/master/example/lib/main.dart

On saved is only triggered when form save is called.

pkmangukiya commented 4 years ago

if we want to call OnSaved on click Save button(Which button is in SelectionModal class file) then how it possible?

oTree-org commented 4 years ago

Hi @hiddencaliber , first of all thank you for this very useful package. I see this same question gets asked many times. I made the same error because the widget has a Save button, so I think it's natural to expect the onSaved callback to relate to that save button. Maybe give the button a different name like "OK" or "continue" to avoid the confusion.

hiddencaliber commented 4 years ago

@oTree-org : Please use "saveButtonText" property to override whatever text you want. Thanks

hiddencaliber commented 3 years ago

All, Please open a new issue, if you still have the problem. Thanks