搜索分类、插件与代码仓

插件详情v0.0.3

variable_app_icon

一个用于在 Android 和 iOS 上使用多个应用图标插件。

AndroidiOS
近 30 天下载
4750
喜欢数
81
Pub 分数
150

安装插件

flutter pub add variable_app_icon

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

variable_app_icon 包允许开发者在 Android 和 iOS 平台上动态更改应用程序图标。它使用户能够在运行时在多个图标之间切换,从而增强个性化和品牌灵活性。这对于希望通过图标反映不同主题、活动或用户偏好的应用程序尤其有用。该插件可无缝集成到 Flutter 项目中,并支持平台特定的图标配置。它需要最少的设置,并与标准的资源管理实践兼容。

适合场景

  • 基于用户偏好的动态图标切换
  • 主题应用图标,用于特殊活动
  • 多租户应用中的品牌定制
  • 个性化应用体验
  • 图标在应用生命周期中的变化

主要特点

  • 支持 Android 和 iOS
  • 运行时图标切换
  • 与 Flutter 的轻松集成
  • 多图标支持
  • 平台特定配置

适合对象

  • 需要图标个性化的应用
  • 基于事件或季节的应用主题
  • 品牌应用
  • 以用户为中心的设计应用
  • 同时针对 iOS 和 Android 的开发者

使用建议

  • 需要手动设置图标资源
  • 仅限支持的平台
  • 可能需要额外的构建步骤
  • 由于政策限制,不适用于所有应用商店
  • 图标更改在某些设备上可能不会立即反映

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

variable_app_icon

A plugin to use multiple app icon on Android and iOS.

If you don't know yet, you can use multiple app icon in an iOS app from 10.3. in android, you can do this using activity-alias. You can accomplish this in your flutter app by using this plugin

Getting Started

First, add variable_app_icon as a dependency in your pubspec.yaml file.

dependencies:
  variable_app_icon: ^0.0.1

Don't forget to flutter pub get.

Usage

1. Setting the app icons (Android)

Drop your app icons into mipmap folders. Then configure android/app/src/main/AndroidManifest.xml as follows.

Why this layout? Activity-aliases are how Android serves multiple launcher icons from one APK, but two known issues require extra care:

  1. Flutter's tooling does not properly follow <activity-alias> for flutter run (flutter/flutter#38965). To make flutter run work, MainActivity must declare android:exported="true" (Android 12+ rule, since it is reachable from adb shell am start) and carry a MAIN + LAUNCHER intent-filter in the source manifest. The LAUNCHER category is then stripped at merge time via tools:node="remove" so MainActivity does not appear as a duplicate launcher icon next to the aliases at runtime.
  2. Some OEM launchers (e.g. Huawei) read app metadata from <application> for the uninstall prompt and system dialogs — see issue #5. Keep android:icon and android:label on <application>.

Use this template (replace your_app_name / mipmap names / activity-alias ids as needed):

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <application
        android:name="${applicationName}"
        android:icon="@mipmap/ic_launcher"
        android:label="your_app_name">

        <!-- One activity-alias per selectable icon. The id (android:name) must contain at least one dot. -->
        <activity-alias
            android:name="appicon.DEFAULT"
            android:enabled="true"
            android:exported="true"
            android:icon="@mipmap/ic_launcher"
            android:label="your_app_name"
            android:targetActivity=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity-alias>

        <!-- Repeat <activity-alias> for each additional icon, with android:enabled="false". -->

        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleTop"
            android:taskAffinity=""
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <meta-data
                android:name="io.flutter.embedding.android.NormalTheme"
                android:resource="@style/NormalTheme" />

            <!-- This intent-filter makes `flutter run` work with the activity-alias setup
                 (flutter/flutter#38965). Flutter's launchable-activity detection reads the
                 source manifest and needs MainActivity to declare MAIN + LAUNCHER; without
                 it, `flutter run` cannot locate MainActivity as launchable. If LAUNCHER
                 survived to runtime, however, MainActivity would appear as a duplicate
                 launcher icon next to the activity-aliases. `tools:node="remove"` strips
                 LAUNCHER at manifest-merge time, satisfying both constraints. -->
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER"
                    tools:node="remove" />
            </intent-filter>
        </activity>

        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
</manifest>

Notes per icon:

  • android:name is the icon id (must contain at least one dot — e.g. appicon.DEFAULT, appicon.TEAL). You pass this id from Dart when calling VariableAppIcon.changeAppIcon.
  • android:enabled="true" on the default icon's alias, android:enabled="false" on the rest.

See example/android/app/src/main/AndroidManifest.xml in this repo for a complete working example with three icons.

2. Setting the app icons (iOS)

Open your ios project i.e. Runner in Xcode, then go to Build Settings tab. Now search icon, you will find Assets Catalog Compiler Options. Set Include All App Icon Assets to Yes. Then add all the icons name to the Alternate App Icon Sets.

3. From the flutter side

In main function set this two variable,

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]

Call this method to change app icon.

 await VariableAppIcon.changeAppIcon(
androidIconId: "appicon.TEAL",
iosIcon: "AppIcon2);

See the example app for complete example.

You are done. Enjoy!

Demo

Android

https://user-images.githubusercontent.com/22527366/191311548-c46fac40-e39f-4286-88c5-05fd6765b5e9.mp4

iOS

https://user-images.githubusercontent.com/22527366/191091356-817b69f0-1a84-4620-87ae-5969d519b4eb.MP4

Support the package (optional)

If you find this package useful, you can support it by giving it a star.

Credits

This package is created by Shahriar Nasim Nafi

所属分类

依赖

依赖清单 1 项

  • plugin_platform_interface^2.0.2

源码仓库

使用此插件的项目

暂无相关数据。