{"id":20463705,"url":"https://github.com/iconfont-cli/flutter-iconfont-cli","last_synced_at":"2025-04-13T08:27:52.238Z","repository":{"id":35134760,"uuid":"207287758","full_name":"iconfont-cli/flutter-iconfont-cli","owner":"iconfont-cli","description":"在flutter中使用iconfont图标，不依赖字体，支持多色彩","archived":false,"fork":false,"pushed_at":"2022-03-24T17:59:11.000Z","size":164,"stargazers_count":85,"open_issues_count":10,"forks_count":17,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-27T00:12:15.697Z","etag":null,"topics":["flutter","flutter-iconfont","fluttter-iconfont-svg","iconfont","iconfont-flutter"],"latest_commit_sha":null,"homepage":null,"language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iconfont-cli.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-09T10:53:24.000Z","updated_at":"2025-01-08T08:08:19.000Z","dependencies_parsed_at":"2022-08-08T05:15:55.187Z","dependency_job_id":null,"html_url":"https://github.com/iconfont-cli/flutter-iconfont-cli","commit_stats":null,"previous_names":["fwh1990/flutter-iconfont-cli"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iconfont-cli%2Fflutter-iconfont-cli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iconfont-cli%2Fflutter-iconfont-cli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iconfont-cli%2Fflutter-iconfont-cli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iconfont-cli%2Fflutter-iconfont-cli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iconfont-cli","download_url":"https://codeload.github.com/iconfont-cli/flutter-iconfont-cli/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248683471,"owners_count":21144910,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["flutter","flutter-iconfont","fluttter-iconfont-svg","iconfont","iconfont-flutter"],"created_at":"2024-11-15T13:12:47.082Z","updated_at":"2025-04-13T08:27:52.213Z","avatar_url":"https://github.com/iconfont-cli.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"## flutter-iconfont-cli\n用纯JS把iconfont.cn的图标转换成Flutter Widget，不依赖字体，支持多色彩\n\n![](https://github.com/fwh1990/flutter-iconfont-cli/blob/master/images/icons.png?raw=true)\n\n## 特性\n\n1、纯组件，不依赖字体，体积小\n\u003cbr /\u003e\n2、支持渲染多色彩图标，支持自定义颜色\n\u003cbr /\u003e\n3、自动化生成图标组件\n\n## Step 1\n\n在项目文件`pubspec.yml`中加入flutter插件 `flutter_svg`\n```yaml\n{\n  ...\n\n  dependencies:\n    # 版本号请以官方库的为准：https://pub.dev/packages/flutter_svg\n    flutter_svg: ^0.19.3\n  ...\n}\n```\n然后执行flutter插件安装操作\n```bash\nflutter packages get\n```\n\n接着安装全局插件（基于nodeJs）\n```bash\nnpm install flutter-iconfont-cli -g\n```\n\n# Step 2\n生成配置文件\n```bash\nnpx iconfont-init\n```\n此时项目根目录会生成一个`iconfont.json`的文件，内容如下：\n```json\n{\n    \"symbol_url\": \"请参考README.md，复制官网提供的JS链接\",\n    \"save_dir\": \"./lib/iconfont\",\n    \"trim_icon_prefix\": \"icon\",\n    \"default_icon_size\": 18,\n    \"null_safety\": true\n}\n```\n### 配置参数说明：\n### symbol_url\n请直接复制[iconfont](http://iconfont.cn)官网提供的项目链接。请务必看清是`.js`后缀而不是.css后缀。如果你现在还没有创建iconfont的仓库，那么可以填入这个链接去测试：`http://at.alicdn.com/t/font_1373348_ghk94ooopqr.js`\n\n\u003cbr /\u003e\n\n![](https://github.com/fwh1990/flutter-iconfont-cli/blob/master/images/symbol-url.png?raw=true)\n\n\n### save_dir\n根据iconfont图标生成的组件存放的位置。每次生成组件之前，该文件夹都会被清空。\n\n### trim_icon_prefix\n如果你的图标有通用的前缀，而你在使用的时候又不想重复去写，那么可以通过这种配置这个选项把前缀统一去掉。\n\n### default_icon_size\n我们将为每个生成的图标组件加入默认的字体大小，当然，你也可以通过传入props的方式改变这个size值\n\n### null_safety\ndart 2.12.0 开始支持的空安全特性，开启该参数后，生成的语法会有所变化，所以需要变更sdk以保证语法能被识别。\n```diff\nenvironment:\n- sdk: \"\u003e=2.7.0 \u003c3.0.0\"\n+ sdk: \"\u003e=2.12.0 \u003c3.0.0\"\n```\n\n# Step 3\n开始生成React标准组件\n```bash\nnpx iconfont-flutter\n```\n生成后查看您设置的保存目录中是否含有所有的图标\n\n-----------\n\n现在，你可以参考[snapshots目录](https://github.com/iconfont-cli/flutter-iconfont-cli/tree/master/snapshots)的快照文件。\n\n# 使用\n\n### 图标尺寸\n根据配置`default_icon_size`，每个图标都会有一个默认的尺寸，你可以随时覆盖。\n```dart\nclass App extends StatelessWidget {\n    @override\n    Widget build(BuildContext context) {\n        return IconFont(IconNames.alipay, size: 100);\n    }\n}\n```\n![](https://github.com/fwh1990/flutter-iconfont-cli/blob/master/images/default-color-icon.png?raw=true)\n### 图标单色\n单色图标，如果不指定颜色值，图标将渲染原本的颜色。如果你想设置为其他的颜色，那么设置一个你想要的颜色即可。\n\n**注意：如果你在props传入的color是字符串而不是数组，那么即使原本是多色彩的图标，也会变成单色图标。**\n\n```dart\nIconFont(IconNames.alipay, color: 'red');\n```\n![](https://github.com/fwh1990/flutter-iconfont-cli/blob/master/images/one-color-icon.png?raw=true)\n\n### 图标多色彩\n多色彩的图标，如果不指定颜色值，图标将渲染原本的多色彩。如果你想设置为其他的颜色，那么设置一组你想要的颜色即可\n```dart\nIconFont(IconNames.alipay, colors: ['green', 'orange']);\n```\n颜色组的数量以及排序，需要根据当前图标的信息来确定。您需要进入图标组件中查看并得出结论。\n\n\n![](https://github.com/fwh1990/flutter-iconfont-cli/blob/master/images/multi-color-icon.png?raw=true)\n\n# 更新图标\n当您在iconfont.cn中的图标有变更时，只需更改配置`symbol_url`，然后再次执行`Step 3`即可生成最新的图标组件\n```bash\n# 修改 symbol_url 配置后执行：\nnpx iconfont-flutter\n```\n\n# 扩展\n|平台|库|\n|----|---|\n|小程序|[mini-program-iconfont-cli](https://github.com/iconfont-cli/mini-program-iconfont-cli)|\n|Taro|[taro-iconfont-cli](https://github.com/iconfont-cli/taro-iconfont-cli)|\n|React H5|[react-iconfont-cli](https://github.com/iconfont-cli/react-iconfont-cli)|\n|React Native|[react-native-iconfont-cli](https://github.com/iconfont-cli/react-native-iconfont-cli)|\n|Remax|[remax-iconfont-cli](https://github.com/iconfont-cli/remax-iconfont-cli)|\n\n--------\n\n欢迎使用，并给我一些反馈和建议，让这个库做的更好\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficonfont-cli%2Fflutter-iconfont-cli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ficonfont-cli%2Fflutter-iconfont-cli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficonfont-cli%2Fflutter-iconfont-cli/lists"}