felixmccuaig / flutter-autocomplete-textfield

An autocomplete Textfield for flutter
MIT License
181 stars 131 forks source link

itemBuilder not responding to SetState. #40

Closed ueabu closed 5 years ago

ueabu commented 5 years ago

I am currently trying to put a checkbox in the builder. The checkbox appears but does not respond when tapped. The value changes but the box itself does not change when the value changes. It remains to be the same color.


....

                  bool isChecked = false;

                   AutoCompleteTextField<String>(
                    suggestions: MySuggestion,
                    itemSubmitted: (item) {
                    setState(() => searchTextField.textField.controller.text =
                          item);                  
                    }
                    itemBuilder: (context, item) {
                     return Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: <Widget>[
                        Text(item,
                            style: TextStyle(
                        fontSize: 16.0
                        ),),
                    Padding(
                padding: EdgeInsets.all(15.0),
                   ),
                    Checkbox(
                         value: isChecked,
                         onChanged: (value) {
                        setState(() {
                        isChecked = value;
                       });
                       print(isChecked);
                        },
                       ),
                      ],
                    );          
                  }
              )`

Does the builder for the suggestion use a different context?

felixmccuaig commented 5 years ago

Yeah probably, but I can't really know for sure without seeing the whole class.

ueabu commented 5 years ago

Would you like to see the whole class ?