颤动字符串到图标值 [英] Flutter String to Icon value

查看:51
本文介绍了颤动字符串到图标值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Flutter中将String值转换为Icons值,我正在从JSON作为字符串获取Icon值.

how to convert String value to Icons value in Flutter, i'm getting Icon value from json as a String.

当我尝试使用该值时出现以下错误

I got following error when i'm tried to Use that value

error: The argument type 'String' can't be assigned to the parameter type 'IconData'. (argument_type_not_assignable at [hippo] lib\screens\dynamic_list.dart:71)

{
  "page": 1,
  "MenuItems": [
    {
      "id": 419701,
      "icon": "MdiIcons.account",
      "name": "account"
    },
    {
      "id": 419702,
      "icon": "MdiIcons.currencyUsd",
      "name": "Funds"
    },
    {
      "id": 419703,
      "icon": "MdiIcons.home",
      "name": "home"
    }
  ]
}

推荐答案

一种方法是可以将图像生成为字体图标(生成为字体).将ttf文件保存在资产中.将unicode数据传递给json(例如"e90a").

one way is that you can generate images to font icon (Generate to font). save ttf file in assets. pass unicode data to json (like "e90a").

例如:

Icon(IconData(int.parse('0x${e90a}',
    fontFamily: 'family name given in the link above'));

这篇关于颤动字符串到图标值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆