简体   繁体   English

如何根据风味更改 Flutter 应用程序图标?

[英]How to change Flutter app ICON depending on flavor?

I want to create different apps flavor on the same base code for production, with the purpose of white labeling.我想在相同的生产基础代码上创建不同的应用程序风格,目的是白标。

I need each flavor to have a different icon/splash screen/name.我需要每种口味都有不同的图标/启动画面/名称。

I was already able to change the app name according to How to change Flutter app name depending on flavor?我已经能够根据如何根据风味更改 Flutter 应用程序名称来更改应用程序名称?

But how do I change the icon (and splash) depending on flavor?但是如何根据口味更改图标(和飞溅)?

The question is both for android and ios.这个问题是针对 android 和 ios 的。

This is an answer specific to android icon:这是特定于 android 图标的答案:

using https://github.com/fluttercommunity/flutter_launcher_icons#flavor-support使用https://github.com/fluttercommunity/flutter_launcher_icons#flavor-support

follow the instruction on this page, but when you run flutter pub run flutter_launcher_icons:main -f <your config file name here> it will override your main res folder.按照此页面上的说明进行操作,但是当您运行flutter pub run flutter_launcher_icons:main -f <your config file name here>时,它将覆盖您的主res文件夹。

So before running this command, make a copy of this folder, then run the command, then copy res folder into a android\app\src\<flavor_name> and restore the original res folder.所以在运行这个命令之前,先复制这个文件夹,然后运行命令,然后将res文件夹复制到一个android\app\src\<flavor_name>并恢复原来的 res 文件夹。

NOTE that for android splash it will also use android\app\src\<flavor_name> so you can customise the splash this way as well请注意,对于 android 启动画面,它还将使用android\app\src\<flavor_name>因此您也可以通过这种方式自定义启动画面

For Android, you should use Flutter Launcher Icons , using their flavors support.对于 Android,您应该使用Flutter Launcher Icons ,使用它们的风格支持。

For iOS, create a {your_flavor_name}.xcconfig file for each flavor, inside ios/Flutter and add to each of them:对于 iOS,在ios/Flutter中为每种风味创建一个 {your_flavor_name}.xcconfig 文件并添加到每个风味:

#include "Generated.xcconfig"
FLUTTER_TARGET=lib/{your_flavor_main.dart_path}
// bundle_suffix used in the bundle id of the app
bundle_suffix=.{your_flavor_bundle}
// the name displayed below the app icon on the home screen
app_display_name={your_app_name}
//FLUTTER_BUILD_MODE=debug

Then, create a image file for each app icon inside Runner/Assets with the name AppIcon${your_flavor_bundle}.然后,为 Runner/Assets 中的每个应用程序图标创建一个名为 AppIcon${your_flavor_bundle} 的图像文件。

Lastly, in XCode navigate to Runner Target -> Build Settings-> Asset Catalog Compiler -> Primary App Icon Set Name .最后,在 XCode 中导航到Runner Target -> Build Settings-> Asset Catalog Compiler -> Primary App Icon Set Name Now add to its value the following name (literally): AppIcon$(bundle_suffix)现在为其值添加以下名称(字面意思): AppIcon$(bundle_suffix)

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

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