Home > Back-end >  Flutter convert List String to List IconData
Flutter convert List String to List IconData

Time:12-22

How can I convert a List<String> to List<IconDate>? I have the following ['Icons.check', 'Icons.cancel'] which I get back from the database, and I need to convert it to ListIconData

I have tried the following

final icons = List<String>.from(widget.values[0]['icons'] as List<IconData>

CodePudding user response:

Try saving the icon's codePoint property to the database.

  IconData parse(int codePoint) {
    return IconData(codePoint, fontFamily: 'MaterialIcons');}

Use it

Icon(parse(0xe139)) // 0xe139 = Icons.cancel.codePoint

CodePudding user response:

Try the following code:

List<IconData> icons = widget.values[0]['icons'].map((String element) => element == 'Icons.check' ? Icons.check : Icons.cancel).toList();
  • Related