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 Error {Either zero or 2 or more [DropdownMenuItem]s were detected with the same value)}

i am trying to make dropdownbutton with using my CustomerModel model instances but i am getting same error again and again . i tried override == operator and add hashcode method for that class but it didn’t fix that error . What can i do for fix this error ?

 Expanded(
                                  child: Container(
                                    padding: const EdgeInsets.symmetric(
                                        horizontal: 10),
                                    decoration: BoxDecoration(
                                        color: Colors.white,
                                        borderRadius: BorderRadius.circular(5),
                                        border: Border.all(color: softColor)),
                                    child: DropdownButton<CustomerModel?>(
                                      dropdownColor: Colors.white,
                                      onChanged: (CustomerModel? value) {
                                        setState(
                                          () {
                                            selectedCustomer = value!;
                                          },
                                        );
                                      },
                                      borderRadius: BorderRadius.circular(5),
                                      isExpanded: true,
                                      icon: Icon(
                                        Icons.arrow_drop_down,
                                        color: softColor,
                                      ),
                                      value:
                                          selectedCustomer ?? allCustomers[0],
                                      items: List.generate(
                                        allCustomers.length,
                                        (index) =>
                                            DropdownMenuItem<CustomerModel>(
                                          child: CustomTextBody(
                                            text:
                                                allCustomers[index].companyName,
                                          ),
                                        ),
                                      ),
                                    ),
                                  ),
                                ),

i tried create dropdownbutton with my class instances but i got error

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

>Solution :

DropdownMenuItem is missing value for your case.

  DropdownMenuItem(
    value: allCustomers[index], //this one
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