0

I have issues with my DropdownButton() in flutter it gives me this error. I don't know what is wrong here....

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 'items' declared as     'List<DropdownMenuItem<T>>?'
                but argument is 'List<DropdownMenuItem<dynamic>>'.

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

This is the snippet of my DropdownButton code.

DropdownButton(
                    items: [
                      DropdownMenuItem(
                        child: Text(
                          'Solar System',
                          style: TextStyle(
                            fontFamily: 'Avenir',
                            fontSize: 24,
                            color: const Color(0x7cdbf1ff),
                            fontWeight: FontWeight.w500,
                          ),
                          textAlign: TextAlign.left,
                        ),
                      ),
                    ],
                    onChanged: (value) {},
                    icon: Padding(
                      padding: const EdgeInsets.only(left: 16.0),
                      child: Image.asset('assets/drop_down_icon.png'),
                    ),
                    underline: SizedBox(),
                  ),
1
  • you forgot your dropdown list. Commented Feb 23, 2022 at 11:44

1 Answer 1

1

You have to specify the type <String> next to DropdownButton and DropdownMenuItem

DropdownButton<String>(
 items: [
  DropdownMenuItem<String>(
   child: Text(
    'Solar System',
    style: TextStyle(
     fontFamily: 'Avenir',
     fontSize: 24,
     color: const Color(0x7cdbf1ff),
     fontWeight: FontWeight.w500,
    ),
    textAlign: TextAlign.left,
   ),
  ),
 ],
 onChanged: (value) {},
 icon: Padding(
  padding: const EdgeInsets.only(left: 16.0),
  child: Image.asset('assets/drop_down_icon.png'),
 ),
 underline: SizedBox(),
),
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.