Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

DropdownButton failed

I have the following DropdownButton widget:

Center(
              child: DropdownButton<dynamic>(
                value: selectedTipoInterno,
                items: dataTiposInt.map(
                  (list) {
                    return DropdownMenuItem(
                      child: Text(list['tipo_int']),
                      value: list['id'],
                    );
                  },
                ).toList(),
                onChanged: (value) {
                  setState(() {});
                },
              ),
            )

And here you have the value for dataTiposInt:

[{"id":"1","tipo_int":"Administrador"},{"id":"2","tipo_int":"Editor"},{"id":"3","tipo_int":"Supervisor"},{"id":"4","tipo_int":"Analista"},{"id":"5","tipo_int":"Colaborador"}]

I am getting the following error output:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

There should be exactly one item with [DropdownButton]'s value: Administrador. 
Either zero or 2 or more [DropdownMenuItem]s were detected with the same value
'package:flutter/src/material/dropdown.dart':
Failed assertion: line 894 pos 15: 'items == null || items.isEmpty || value == null ||
              items.where((DropdownMenuItem<T> item) {
                return item.value == value;
              }).length == 1'

>Solution :

I wish I could just do a little comment but don’t have enough reputation yet.

Is the value for datatiposInt written like that in your code? Or is it generated? If the latter, it might be helpful to see that code as well.

Also, I’m guessing that your selectedTipoInterno is not of type String, so I’m wondering if that throws off the dropdown in general

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading