Failed assertion: line1606pos15: 'items==null||items.isEmpty || value==null||items.where((DropdownMenuItem<T>item){return item.value=value;}).length=1

19 views Asked by At

I made a dropdownbutton of state and a dropdownbutton of city that depends on me to select the state it changes the city, the first one works perfectly but when I select the city it generates an error

Below we have the variables and the code itself of the dropdownbuttons dependent pore generates the title error

Failed assertion: line1606pos15: 'items==null||items.isEmpty || value==null||items.where((DropdownMenuItemitem){return item.value=value;}).length=1

//variables

var estado = {'Parana' : 'PR', 'Santa Catarina' : 'SC', 'Rio Grande do Sul' : 'RS'};
  String _selecionaEstado = 'Parana';

  final List _estados = [];
  EstadoDependentDropDown(){
    estado.forEach((key, value) {
      _estados.add(key);
    });
    _selecionaEstado = _estados[0];
  }

  var cidade = {'União da Vitoria' : 'PR', 'Guarapuava' : 'PR', 'Canoinhas' : 'SC', 'Tubarão' : 'SC', 'Xanxerê' : 'RS', 'Gramado' : 'RS'};

  String _selecionaCidade = 'União da Vitoria';

  List _cidades = [];
  CidadeDependentDropDown(estadoShortName){
    cidade.forEach((key, value) {
      if(estadoShortName == value){
        _cidades.add(key);
      }
    });
    _selecionaCidade = _cidades[0];
  }

//row_dropdownbutton

Container(
                        child: DropdownButtonFormField<String>(
                          isExpanded: true,
                          value: _selecionaEstado,
                          onChanged: (newValue) {
                            setState(() {
                              _cidades = [];
                              CidadeDependentDropDown(estado[newValue]);
                              _selecionaEstado = '$newValue';
                            });
                          },
                          items: _estados.map((estado){
                            return DropdownMenuItem(
                              child: Text((estado).toString()),
                              value: estado.toString(),
                            );
                          }).toList(),
                        ),
                      ),
SizedBox(
                        child: DropdownButtonFormField<String>(
                          isExpanded: true,
                          value: _selecionaCidade,
                          onChanged: (newValue) {
                            setState(() {
                              _selecionaEstado = '$newValue';
                            });
                          },
                          items: _cidades.map((estado){
                            return DropdownMenuItem(
                              child: Text((estado).toString()),
                              value: estado.toString(),
                            );
                          }).toList(),
                        ),
                      ),                                            
0

There are 0 answers