如何通过代码点获取正确的Google Icons图标?解决显示错误问题
解决Material Symbols Outlined信息图标显示错误的问题
以下是关键修复步骤:
修正字体家族名称
你当前使用的'Material+Symbols+Outlined:opsz'是Google Fonts的加载参数,并非字体的实际家族名称。正确的家族名应为MaterialSymbolsOutlined(无空格和特殊符号)。确保字体正确导入
如果使用google_fonts包:- 在
pubspec.yaml中添加依赖:dependencies: google_fonts: ^6.1.0 - 代码中通过GoogleFonts获取正确的字体家族:
import 'package:google_fonts/google_fonts.dart'; Icon icn = Icon( IconData(0xe88e, fontFamily: GoogleFonts.materialSymbolsOutlined().fontFamily), size: 20.0, color: Color.fromARGB(255, 253, 183, 6), );
如果是本地导入字体文件:
- 下载
MaterialSymbolsOutlined.ttf文件,放到项目的assets/fonts/目录下 - 在
pubspec.yaml中配置字体:flutter: fonts: - family: MaterialSymbolsOutlined fonts: - asset: assets/fonts/MaterialSymbolsOutlined.ttf - 代码中直接使用
fontFamily: 'MaterialSymbolsOutlined'
- 在
验证代码点与字体变体匹配
确认0xe88e确实是Material Symbols Outlined版本信息图标的代码点,不同变体(如Filled、Rounded、Sharp)的代码点可能不同,需核对对应变体的代码点。可选:指定光学大小(opsz)
Material Symbols支持光学大小调整,若需要匹配设计需求,可在加载字体时指定:final symbolFont = GoogleFonts.materialSymbolsOutlined(fontOpticalSize: 24); Icon icn = Icon( IconData(0xe88e, fontFamily: symbolFont.fontFamily), size: 20.0, color: Color.fromARGB(255, 253, 183, 6), );
内容的提问来源于stack exchange,提问作者Güven Acar
相关产品推荐
相关产品推荐

