1

Hello Flutter Development Experts, I want to make DropdownButton widget to show given items, but I am facing an error ehich is below descrived. I do not know the exact solution. I tried many things even searced on google but, did not get exact answer.

Error: Couldn't infer type parameter 'T'.

Tried to infer 'dynamic' for 'T' which doesn't work: Parameter 'onChanged' declared as 'void Function(T?)?' but argument is 'void Function(Object?)'. The type 'dynamic' was inferred from: Parameter 'value' declared as 'T?' but argument is 'String'. Parameter 'items' declared as 'List<DropdownMenuItem>?' but argument is 'List<DropdownMenuItem>'.

Consider passing explicit type argument(s) to the generic.

-------------_------- I hope it is clear and understandable.

String dropDownValue = 'Ahmedabad';

 DropdownButton(
                  value: dropDownValue,
                  icon: const Icon(Icons.arrow_drop_down_outlined),
                  items: List.generate(
                    6,
                    (index) => DropdownMenuItem(
                      child: Container(
                        padding: const EdgeInsets.all(8),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                          children: [
                            Image.asset('ahmdabaf.jpg'),
                            const Text('Ahmedabad'),
                          ],
                        ),
                      ),
                    ),
                  ),
                  onChanged: (newValue) {
                    setState(() {});
                  },
                )

1 Answers1

3

Try providing data type like

DropdownButton<String>(
  value:  // this must be included on DropdownMenuItem's value

And make sure to include value on `DropdownMenuItem``

6,
(index) => DropdownMenuItem<String>(
  value:  , // your string value,
Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56