variable_app_icon
一个可在 Android 和 iOS 上使用多个应用图标的插件。
如果您还不知道,可以在 iOS 应用中使用多个应用图标(从 10.3 版本开始),在 Android 中,您可以使用 activity-alias 来实现。您可以使用此插件在 Flutter 应用中实现此功能。
入门
首先,将 variable_app_icon 添加到 pubspec.yaml 文件的依赖项中。
dependencies:
variable_app_icon: ^0.0.1
别忘了运行 flutter pub get。
用法
1. 设置应用图标 (Android)
将您的应用图标放入 mipmap 文件夹。然后在 AndroidManifest.xml 中,为每个图标使用如下方式:
<!-- Use this for each icon -->
<activity-alias
android:name="appicon.DEFAULT" <!-- here is your icon id, this can be anything but keep at least one dot -->
android:enabled="true" <!-- set true for default icon, for others' set false-->
android:exported="true"
android:icon="@mipmap/ic_launcher" <!-- icon location-->
android:label="variable_app_icon_example"
android:targetActivity=".MainActivity"> <!-- main activity -->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>
删除 application 标签的 label 和 icon 属性。
从主活动的 <intent-filter> 中删除 <category android:name="android.intent.category.LAUNCHER" />。
2. 设置应用图标 (iOS)
在 Xcode 中打开您的 iOS 项目,即 Runner,然后转到 Build Settings 选项卡。
现在搜索 icon,您会找到 Assets Catalog Compiler Options。将 Include All App Icon Assets 设置为 Yes。
然后将所有图标名称添加到 Alternate App Icon Sets。 ![]()
3. 从 Flutter 端
在 main 函数中设置这两个变量:
VariableAppIcon.iOSDefaultAppIcon = iosAppIcons[0]; // default ios icon
VariableAppIcon.androidAppIconIds = androidIconIds; // all android icons ids, this is the android:name, you have specified in `AndroidManifest.xml` file. like, ["appicon.DEFAULT", others]
调用此方法来更改应用图标。
await VariableAppIcon.changeAppIcon(
androidIconId: "appicon.TEAL",
iosIcon: "AppIcon2);
请参阅示例应用以获取完整示例。
您已完成。祝您使用愉快!
演示
Android
AndroidExample.mp4
iOS
RPReplay_Final1663612728.MP4
支持该软件包(可选)
如果您觉得此软件包有用,可以通过给它一个星来支持它。
鸣谢
此软件包由 Shahriar Nasim Nafi 创建