字体图标不在我的Flutter应用程序中工作

12

我目前正在进行一个副业项目,当我在我的应用程序中包含了一个 font-awesome 图标时,它没有显示出来,而是显示为一个空白框,其中有两条相交的线,就像字母 x 一样。如何解决这个问题?

class ImageHoldingComponent extends StatefulWidget {
  @override
   _ImageHoldingComponentState createState() => 
 _ImageHoldingComponentState();
class _ImageHoldingComponentState extends State<ImageHoldingComponent> {
  @override
  Widget build(BuildContext context) {
    return Container(
   child: Icon(FontAwesomeIcons.python)
      );
  }
}
5个回答

41
font_awesome_flutter包的作者建议对于那些遇到图标无法显示问题的人执行以下步骤:
  1. 停止应用程序
  2. 在您的应用程序目录中运行flutter clean
  3. 从模拟器/仿真器/设备中删除应用程序
  4. 重新构建并部署应用程序。

还要确保在pubspec.yaml文件中将uses-material-design设置为true


6
这是因为您开始使用旧版本的font_awesome_flutter并且虚拟设备缓存在构建Flutter应用程序时被存储,所以每次更改图标都必须停止模拟器并重新构建。我的经验是:
1. 停止main.dart(Android模拟器)。 2. 在pubspec.yaml中添加(font_awesome_flutter)新版本。
``` font_awesome_flutter: ^8.8.1 ```
dependencies:
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.2
  font_awesome_flutter: ^8.8.1 //new verison

然后点击

"Pub get"

在Flutter命令的顶部

  1. 再次运行模拟器(启动main.dart)

3

如果您的应用程序正在模拟器或设备上运行,只需停止它并再次启动即可解决问题。


0

只需将pupspec.yaml文件保存在依赖项下,然后运行pub get命令,别忘了导入它


你的回答可以通过提供更多支持信息来改进。请编辑以添加进一步的细节,例如引用或文档,以便他人可以确认你的答案是正确的。您可以在帮助中心中找到有关如何编写良好答案的更多信息。 - Community

0
将 font_awesome_flutter: ^10.3.0 包添加到 pubspec.yaml 文件中。 然后像这样使用。
    FaIcon(
           Icons.access_alarm,
           color: whatsappColor,
           size: 30,
          ),

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接