简体   繁体   English

Flutter 启动器图标没有改变?

[英]Flutter Launcher icon not getting changed?

Am new to Flutter. I gone through the flutter documentation and followed the steps to configure custom launcher icons for my flutter project but app Launcher icon is not getting changed?我是 Flutter 的新手。我阅读了 flutter 文档并按照步骤为我的 flutter 项目配置自定义启动器图标,但应用程序启动器图标没有更改? Not sure what am missing.不确定缺少什么。

在此处输入图像描述

Code:代码:

dev_dependencies:
  flutter_test:
    sdk: flutter  
  flutter_launcher_icons: "^0.7.0"

flutter_icons:
  image_path: "icon/icon.png"
  android: true 
  ios: true

您必须获取包,然后运行以下命令来更改图标。

 $ flutter pub pub run flutter_launcher_icons:main
  1. Add flutter_launcher_icons: ^0.7.3 code Plugin to pubspec.yamlflutter_launcher_icons: ^0.7.3代码插件添加到 pubspec.yaml

  2. in pubspec.yaml :pubspec.yaml 中:

     flutter_icons: image_path_android: "images/logoapp.png" image_path_ios: "images/logoapp.png" android: true ios: true
  3. run command : flutter pub get运行命令: flutter pub get

  4. run command : flutter pub pub run flutter_launcher_icons:main运行命令: flutter pub pub 运行 flutter_launcher_icons:main

  5. run command : flutter clean运行命令: flutter clean

  6. run command : flutter run运行命令:颤动运行

it worked for me它对我有用

Able to change Now after following below Steps.遵循以下步骤后可以立即更改。

  1. Add flutter_launcher_icons code Plugin to pubspec.yaml as mentioned in question如问题所述,将 flutter_launcher_icons 代码插件添加到 pubspec.yaml
  2. In Command prompt run below commands在命令提示符下运行以下命令
    • flutter pub get扑扑酒吧得到
    • flutter pub pub run flutter_launcher_icons:main flutter pub pub 运行 flutter_launcher_icons:main
  3. And it worked它起作用了
  4. Launcher Icons I generated using external website https://romannurik.github.io/AndroidAssetStudio/icons-launcher.html我使用外部网站https://romannurik.github.io/AndroidAssetStudio/icons-launcher.html生成的启动器图标

there is two way to update app icon有两种方法可以更新应用程序图标

1) first way 1)第一种方式

dev_dependencies:
  flutter_test:
    sdk: flutter  

  flutter_launcher_icons: "^0.7.5"

flutter_icons:
  image_path: "icon/appicon.png"
  android: true 
  ios: true

run this two command运行这两个命令

flutter pub get

flutter pub run flutter_launcher_icons:main

2) if above not work then below solutions (change in native) 2)如果以上不起作用,那么下面的解决方案(原生变化)

you can change appicon from Image Asset, right click on main folder of your project structure and go new -> Image Asset , now just select your icon and finish it, Android studio will generate all necessary icons for you.您可以从 Image Asset 更改 appicon,右键单击项目结构的主文件夹并转到 new -> Image Asset ,现在只需选择您的图标并完成它,Android Studio 将为您生成所有必要的图标。

这里看图像资产

similarly you can change appicon for ios, go同样,您可以更改 ios 的 appicon,去

ios -> Runner -> Assets.xcassets -> Appicon.appiconset ios -> Runner -> Assets.xcassets -> Appicon.appiconset

then replace icons with your new icons然后用你的新图标替换图标

that's it!就是这样!

I wasn't using flutter_launcher_icons , I was using just Image Asset Studio in the Android project.我没有使用flutter_launcher_icons ,我在 Android 项目中只使用了 Image Asset Studio。 It seemed that in certain situations it wasn't updating my Adaptive Icon on Android.似乎在某些情况下它不会更新我在 Android 上的自适应图标。

To fix it, I opened the Android module (right click on the android/ folder in the Flutter view, then select Flutter | Open Android Module in Android Studio).为了修复它,我打开了 Android 模块(在 Flutter 视图中右键单击android/文件夹,然后选择 Flutter | Open Android Module in Android Studio)。 From there, open the res/ folder and delete everything that looks like foreground.xml .从那里,打开res/文件夹并删除所有看起来像foreground.xml AFAICT this is what is generated by Image Asset Studio as part of the Adaptive Icon. AFAICT 这是由 Image Asset Studio 生成的,作为自适应图标的一部分。

Then recreate the Adaptive Icon via Image Asset Studio.然后通过 Image Asset Studio 重新创建自适应图标。

At this point my Flutter cache was corrupted, so I had to run flutter pub cache repair (I mention this because maybe somehow that is what fixed it, but I doubt it).此时我的 Flutter 缓存已损坏,所以我不得不运行flutter pub cache repair (我提到这一点是因为可能以某种方式修复了它,但我对此表示怀疑)。 Run the app and then voila, the icon updated.运行应用程序,然后瞧,图标更新了。

For me the folder drawable-v24 was a problem.对我来说,文件夹drawable-v24是一个问题。 After removing foreground.xml from there it worked.从那里删除foreground.xml后,它起作用了。

First add flutter_launcher_icons: ^0.8.1 code Plugin to pubspec.yaml首先在pubspec.yaml中添加flutter_launcher_icons: ^0.8.1 code Plugin

in pubspec.yaml file:在 pubspec.yaml 文件中:

  1. flutter_icons: image_path_android:"images/logoapp.png" image_path_ios:"images/logoapp.png" android:true ios:true flutter_icons: image_path_android:"images/logoapp.png" image_path_ios:"images/logoapp.png" android:true ios:true

  2. check iOS -Folder -> Runner -> Assets.xcassets -> AppIcon.appiconset: if duplicates exist delete them.检查 iOS -Folder -> Runner -> Assets.xcassets -> AppIcon.appiconset:如果存在重复项,则删除它们。

run commands : flutter pub get run commands : flutter pub pub run flutter_launcher_icons:main run commands : flutter clean run commands : flutter run运行命令:flutter pub get 运行命令:flutter pub pub run flutter_launcher_icons:main 运行命令:flutter clean 运行命令:flutter run

This worked for me.这对我有用。

For anyone getting any errors when they try to run flutter pub pub run flutter_launcher_icons:main , you may have not added Flutter to PATH.对于在尝试运行flutter pub pub run flutter_launcher_icons:main时遇到任何错误的任何人,您可能没有将 Flutter 添加到 PATH。 Follow this answer here to add Flutter to Path.按照此处的答案将 Flutter 添加到 Path。

Those who had faced problems in changing the flutter icon in VS code, go to android/app/build.gradle.那些在 VS 代码中更改颤振图标时遇到问题的人,请转到 android/app/build.gradle。 Then change the value of the following two properties:然后更改以下两个属性的值:

// minSdkVersion 26
// targetSdkVersion 30

Then the same process.然后同样的过程。

I realized that there is a Contents.json file under ios/Runner/Assets.xcassets/AppIcon.appiconset that contains the name of the previous png files, which didn't match the new files that was replaced in that folder.我意识到在ios/Runner/Assets.xcassets/AppIcon.appiconset下有一个Contents.json文件,其中包含先前 png 文件的名称,该文件与该文件夹中替换的新文件不匹配。

I properly updated the json file with the new file names, then removed the application on my simulator and run the build again.我用新的文件名正确更新了 json 文件,然后在我的模拟器上删除了应用程序并再次运行构建。 Then I could see the new icon on ios.然后我可以看到 ios 上的新图标。

Just run the following flutter_launcher_icon and then run your app.只需运行以下flutter_launcher_icon ,然后运行您的应用程序。

If you have flavors in IOS,如果IOS有口味,

Goto Xcode > Runner > Build Settings > Asset Catalog Compiler - options > Primary App Icon Set Name and add values for each flavor转到Xcode > Runner > Build Settings > Asset Catalog Compiler - options > Primary App Icon Set Name并为每种口味添加值

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM