codegrue / card_settings

A flutter package for building card based forms.
https://pub.dartlang.org/packages/card_settings
MIT License
555 stars 103 forks source link

There is not TextEditingController () in CardSettingsListPicker () #151

Closed robertoltrocha closed 3 years ago

robertoltrocha commented 3 years ago

Hi,

Maybe it is a simple question, but I am not finding a way to change the value in a CardSettingsListPicker () in runtime mode because there is no TextEditingController for this widget, could anyone help?

I need to change the value of a CardSettingsListPicker () depending on the value chosen in another CardSettingsListPicker (). How could I do it? thanks.

CardSettingsListPicker(
                                    key: _statusKey,
                                    showMaterialonIOS: true,
                                    fieldPadding: EdgeInsets.only(top: 15, bottom: 15, left: 10, right: 10),
                                    label: "Status",
                                    initialValue: armario.status,
                                    values: ConfigStrings.listStatusArmario.map((el) => el.armarioid).toList(),
                                    options: ConfigStrings.listStatusArmario.map((el) => el.descricao).toList(),
                                    onSaved: (value) {
                                      armario.status = value;
                                    },
                                    onChanged: (value) {
                                      armario.status = value;
                                      if (value == "Livre" || value == "Danificado") {
                                        setState(() {
                                          _controllerSetor.clear();
                                          _controllerTurno.clear();
                                          _controllerMatricula.clear();
                                        });
                                      }
                                    },
                                  ),
                                  CardSettingsListPicker(
                                    key: _nomeKey,
                                    showMaterialonIOS: true,
                                    fieldPadding: EdgeInsets.only(top: 15, bottom: 15, left: 10, right: 10),
                                    label: "Nome",
                                    initialValue: armario.cpf != "" ? armario.cpf : "",
                                    values: widget.empregados.map((el) => el.cpf).toList(),
                                    options: widget.empregados.map((el) => el.nomeEmpregado).toList(),
                                    onSaved: (value) {
                                      setState(() {
                                        armario.cpf = value;
                                      });
                                    },
                                    onChanged: (value) {
                                      setState(() {
                                        armario.cpf = value;
                                        urlfoto = widget.empregados
                                            .where((element) => element.cpf == armario.cpf)
                                            .first
                                            .urlFoto
                                            .toString();
                                        _controllerTurno.text = widget.empregados
                                            .where((element) => element.cpf == armario.cpf)
                                            .first
                                            .turnoDescricao
                                            .toString();
                                        _controllerSetor.text = widget.empregados
                                            .where((element) => element.cpf == armario.cpf)
                                            .first
                                            .setorDescricao
                                            .toString();
                                        _controllerMatricula.text =
                                            widget.empregados.where((element) => element.cpf == armario.cpf).first.matricula.toString();
                                        _controllerFuncao.text = widget.empregados
                                            .where((element) => element.cpf == armario.cpf)
                                            .first
                                            .funcaoDescricao
                                            .toString();
                                      });
                                    },
                                  ),
codegrue commented 3 years ago

I would wrap this in a custom widget and rebuild it when the dependent data changes. You want to change the initial value basically.