1

I'm new to Android Studio and Flutter. I'm trying to make a list of icons that I can iterate into a ListView.

I receive this error: The element type 'IconData' can't be assigned to the list type 'Icon'.

For doing this:

   static const _iconTypes = <Icon>[
   Icons.cake,
   Icons.add_location_sharp,
   Icons.zoom_in_outlined,
   Icons.auto_awesome_motion,
   Icons.call_end_sharp,
   Icons.equalizer_rounded,
   Icons.wifi_lock,
   Icons.mail,
  ];

Is <icon> an incorrect datatype to use here?

Thanks

3 Answers 3

3

It should be IconData

  static const _iconTypes = <IconData>[
    Icons.cake,
    Icons.add_location_sharp,
    Icons.zoom_in_outlined,
    Icons.auto_awesome_motion,
    Icons.call_end_sharp,
    Icons.equalizer_rounded,
    Icons.wifi_lock,
    Icons.mail,
  ];

And you can use it like

    ...
     Container(
      child: ListView(
        children: _iconTypes.map((icon) => Icon(icon)).toList(),
      ),
    )
    ...
Sign up to request clarification or add additional context in comments.

Comments

2

Do this instead:

List<IconData> _iconTypes = [ 
 Icons.cake,
 Icons.add_location_sharp,
 Icons.zoom_in_outlined,
 Icons.auto_awesome_motion,
 Icons.call_end_sharp,
 Icons.equalizer_rounded,
 Icons.wifi_lock,
 Icons.mail,
];

If this still doesn't work please include your ListView also in the question.

Comments

0
    final  List<IconData> icons = [
    Icons.sentiment_very_dissatisfied,
    Icons.home,
    Icons.drafts,
    Icons.backspace
];

I hope You can easily use this in your widgets.

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.