简体   繁体   English

Flutter 图标不显示

[英]Flutter icons do not show

I am trying to complete this Flutter Code Lab, but the icons do not appear in my application.我正在尝试完成这个Flutter 代码实验室,但图标没有出现在我的应用程序中。 But they appears in Android Studio code:但它们出现在 Android Studio 代码中: 在此处输入图像描述 I have been included the lib in my file pubspec.yaml我已将 lib 包含在我的文件pubspec.yaml

name: startup_namer
description: A new Flutter application.

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^0.1.0
  english_words: ^3.1.0

But result is this:但结果是这样的: 在此处输入图像描述

My main.dart file looks like this:我的 main.dart 文件如下所示:

// Add the heart icons to the ListView.

import 'package:flutter/material.dart';
import 'package:english_words/english_words.dart';


void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {

   ..... 

  Widget _buildRow(WordPair pair) {
    final bool alreadySaved = _saved.contains(pair);

    return new ListTile(
      title: new Text(
        pair.asPascalCase,
        style: _biggerFont,
      ),
      trailing: new Icon(
        alreadySaved ? Icons.favorite : Icons.favorite_border,
        color: alreadySaved ? Colors.red : null,
        size: 22.0,
      ),
      onTap: () {      
        setState(() {
          if (alreadySaved) {
            _saved.remove(pair);
          } else {
            _saved.add(pair);
          }
        });
      },
    );
  }
}

I thought that is because I use iOS emulator, but when I tried with Android emulator the result was the same.我以为那是因为我使用 iOS 模拟器,但是当我尝试使用 Android 模拟器时,结果是一样的。

(Copied from the comments) (复制自评论)

You need to set uses-material-design: true in pubspec.yaml for the icons to be included in the app.您需要在pubspec.yaml设置uses-material-design: true pubspec.yaml将图标包含在应用程序中。

In my case, I have written uses-material-design: true in pubspec.yaml file.就我而言,我在pubspec.yaml文件中编写了uses-material-design: true I am able to solve this problem by restarting the Android emulator.我可以通过重新启动 Android 模拟器来解决这个问题。 You can also try by uninstalling old build from your emulator and then installing the new one.您也可以尝试从模拟器中卸载旧版本,然后安装新版本。

This is little weird behavior, but it works for me.这是有点奇怪的行为,但它对我有用。

如果您使用 FlutterIcons 库,请确保 pubspec.yaml 中的字体系列与my_flutter_app_icons.dart文件中声明的字体系列相匹配。

Hot reloading does not show changes in resources.热重载不会显示资源的变化。 Press the stop button square red color in the top action menu bar of android studio and run the app again.按下android studio顶部操作菜单栏中的红色方形停止按钮,然后再次运行该应用程序。

黑色圆圈突出显示的红色图标 It works.有用。

I assume we're talking about the flutter_icons package?我假设我们在谈论flutter_icons包?

I had to kill the app entirely and reinstall it and they started working for me.我不得不完全终止该应用程序并重新安装它,然后他们开始为我工作。 Not sure why a hot reload didn't do the trick.不知道为什么热重载不起作用。

Just delete the App from emulator/physical device on which you are working and again build the app.只需从您正在工作的模拟器/物理设备中删除该应用程序,然后再次构建该应用程序。 It works for me and will surely works for you.它对我有用,肯定对你有用。

You need to set uses-material-design: true in pubspec.yaml for the icons to be included in the app.您需要在 pubspec.yaml 中设置 uses-material-design: true 才能将图标包含在应用程序中。

Be sure to have a uses-material-design: true entry in the flutter section of your pubspec.确保在你的 pubspec 的 flutter 部分有一个 uses-material-design: true 条目。 yaml file. yaml 文件。 It allows you to use the predefined set of Material icons.它允许您使用预定义的材料图标集。 Many Material Design widgets need to be inside of a MaterialApp to display properly, in order to inherit theme data.许多 Material Design 小部件需要在 MaterialApp 内部才能正确显示,以便继承主题数据。

Please try:请尝试:

  1. Stopping the app停止应用程序
  2. Running flutter clean in your app directory在您的应用程序目录中运行 flutter clean
  3. Deleting the app from your simulator / emulator / device从模拟器/模拟器/设备中删除应用程序
  4. Rebuild & Deploy the app.重建和部署应用程序。

Icon changing to Chinese character was resolved by adding the correct path to the fonts folder.通过将正确的路径添加到字体文件夹来解决图标更改为中文字符的问题。 Specify, the correct path to your fonts folder by providing proper indentations:通过提供适当的缩进来指定字体文件夹的正确路径:

  • Flutter Clean颤振清洁
  • Remove Build From your testing device/Emulator从您的测试设备/模拟器中删除构建
  • Run the app运行应用程序

this was issue for me这对我来说是个问题

Make sure in pubspec.yaml file all the images and fonts have correct path and if you have added new image recently try to remove that and then rebuild确保在 pubspec.yaml 文件中所有图像和字体都有正确的路径,如果您最近添加了新图像,请尝试删除它然后重建

The icons were loading normally on all devices except android for me.对我来说,除了 android 之外的所有设备上的图标都正常加载。 To fix it I simply:为了解决它,我只是:

Before

Icon(
       Icons.chevron_left,
          size: 40.0,
          color: Colors.white,
        ),

在此处输入图片说明

After

  Icon(

       MdiIcons.chevronLeft,
          size: 40.0,
          color: Colors.white,
        ),

在此处输入图片说明

Steps脚步

  1. Add to pubspec yahml添加到 pubspec yahml

dependencies: material_design_icons_flutter: ^4.0.5955依赖项:material_design_icons_flutter:^4.0.5955

  1. Add this to the file you want the icon将此添加到您想要图标的文件中

import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';导入'包:material_design_icons_flutter/material_design_icons_flutter.dart';

  1. Instead of Icons.NameHere use MdiIcon.NameHere而不是 Icons.NameHere 使用 MdiIcon.NameHere

The problem started in my project when I included my app within GetMaterialApp instead of MaterialApp Widget.当我将我的应用程序包含在GetMaterialApp而不是MaterialApp Widget 中时,问题就出现在我的项目中。 All Material icons started to look like [X].所有材质图标开始看起来像 [X]。

Add the following to your pubspec.yaml:将以下内容添加到您的 pubspec.yaml 中:

flutter: 
  uses-material-design: true

Took me a while to figure out based on the answers above that uses-material-design is a property of flutter , not of the root.我花了一段时间才根据上面的答案弄清楚uses-material-designflutter的属性,而不是根的属性。

if all the above not worked then run flutter pub run flutter_launcher_icons:main如果以上所有方法均无效,则运行 flutter pub run flutter_launcher_icons:main

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 android studio / flutter 图标建议不显示 - android studio / flutter icons suggestions do not show Flutter 图标不会显示在应用程序栏中,但它可以在正文中使用 - Flutter icons do not show in app bar but it works in body 图标无法正确显示 - Icons Won't Show Up Correctly Flutter Flutter:根据值显示不同的图标 - Flutter: Show different icons based on value Flutter 图标如何真正起作用,以及是什么呈现图标? - How do Flutter Icons really work, and what renders the icons? 如何使用下拉按钮创建 TextformField 以在 flutter 中显示图标和文本列表 - How to create TextformField with Dropdown button to show list of icons and text in flutter flutter 启动器图标的问题,成功安装后它不会在我的 android 设备中显示启动器图标 - issue with flutter launcher icons, after successfully installed it doesn't show the launcher icons in my android device 如何在flutter中将一个图标更改为两个不同的图标? - How do I change one icon into two different icons in flutter? 问题:我的应用程序上没有出现 Flutter 图标? (仅在我的电脑上) - Problem: Flutter icons do not appear on my application? (only on my PC) 如何使用 flutter 调整列表和图标的 position? - How do I adjust the position of lists and icons in them with flutter?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM