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

why Doesn't see List type?

I am using declare an array –

  final List<DropdownMenuItem<String>> listDropDown;

And I use the following construction –

class DropDown extends StatelessWidget {

  final String dropDownValue;
  final List<DropdownMenuItem<String>> listDropDown;

  DropDown(this.dropDownValue, this.listDropDown);

But I get an 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

The argument type 'List<dynamic>' can't be assigned to the parameter type 'List<DropdownMenuItem<String>>?'.

In this place –

return DropdownMenuItem(
                      value: dropDownValue,
                      child: Text(items, style: TextStyle(fontFamily: "Mark-Pro", fontSize: 18, fontWeight: FontWeight.w500, color: configColors.darkBlue),),
                    );
                  }).toList(),

full dropDownButtom –

child: DropdownButton(
                  items: listDropDown.map((String items) {
                    return DropdownMenuItem(
                      value: dropDownValue,
                      child: Text(items, style: TextStyle(fontFamily: "Mark-Pro", fontSize: 18, fontWeight: FontWeight.w500, color: configColors.darkBlue),),
                    );
                  }).toList(),
                  // Initial Value
                  value: dropDownValue,

                  // Down Arrow Icon
                  icon: const Icon(Icons.keyboard_arrow_down),

                  // Array list of items

                  // After selecting the desired option,it will
                  // change button value to selected value
                  onChanged: (String? newValue) {
                    mystate(() {
                      dropDownValue = newValue!;
                    });
                  },
                ),

>Solution :

The issue is in calling DropDown, you are passing List instead of List<DropdownMenuItem> to DropDown’s listDropDown.

try this:

DropdownButton<String>(
                  items: listDropDown.map((String items) {
                    return DropdownMenuItem<String>(
                      value: dropDownValue,
                      child: Text(items, style: TextStyle(fontFamily: "Mark-Pro", fontSize: 18, fontWeight: FontWeight.w500, color: configColors.darkBlue),),
                    );
                  }).toList(),
                  // Initial Value
                  value: dropDownValue,

                  
                  icon: const Icon(Icons.keyboard_arrow_down),
                  onChanged: (String? newValue) {
                    mystate(() {
                      dropDownValue = newValue!;
                    });
                  },
                )
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