Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tastelessjolt/flutter_dynamic_icon
A flutter plugin for dynamically changing app icon and app icon batch number
https://github.com/tastelessjolt/flutter_dynamic_icon
Last synced: about 2 months ago
JSON representation
A flutter plugin for dynamically changing app icon and app icon batch number
- Host: GitHub
- URL: https://github.com/tastelessjolt/flutter_dynamic_icon
- Owner: tastelessjolt
- License: bsd-3-clause
- Created: 2019-02-10T17:02:06.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-28T13:01:04.000Z (over 1 year ago)
- Last Synced: 2024-06-19T07:39:46.585Z (3 months ago)
- Language: Dart
- Size: 5.85 MB
- Stars: 93
- Watchers: 4
- Forks: 43
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# flutter_dynamic_icon
A flutter plugin for dynamically changing app icon and app icon batch number in the mobile platform. Supports **only iOS** (with version > `10.3`).
## Usage
To use this plugin, add `flutter_dynamic_icon` as a [dependency in your pubspec.yaml file](https://flutter.io/platform-plugins/).
## Getting Started
Check out the `example` directory for a sample app using `flutter_dynamic_icon`.
### iOS Integration
#### Index
* `2x` - `120px x 120px`
* `3x` - `180px x 180px`To integrate your plugin into the iOS part of your app, follow these steps
1. First let us put a few images for app icons, they are
* `[email protected]`, `[email protected]`
* `[email protected]`, `[email protected]`,
* `[email protected]`, `[email protected]`,
2. These icons shouldn't be kept in `Assets.xcassets` folder, but outside. When copying to Xcode, you can select 'create folder references' or 'create groups', if not you will get and error when uploading the build to the AppStore saying: (Thanks to @nohli for this observation)
`TMS-90032: Invalid Image Path - - No image found at the path referenced under key 'CFBundleAlternateIcons':...`Here is my directory structure:
![directory_structure](https://raw.githubusercontent.com/tastelessjolt/flutter_dynamic_icon/master/imgs/directory_structure.png)
3. Next, we need to setup the `Info.plist`
1. Add `Icon files (iOS 5)` to the Information Property List
2. Add `CFBundleAlternateIcons` as a dictionary, it is used for alternative icons
3. Set 3 dictionaries under `CFBundleAlternateIcons`, they are correspond to `teamfortress`, `photos`, and `chills`
4. For each dictionary, two properties — `UIPrerenderedIcon` and `CFBundleIconFiles` need to be configured
5. If the sub-property `UINewsstandIcon` is showing under `Icon files (iOS 5)` and you don't plan on using it (it is intended for use with Newstand features), erase it or the app will get rejected upon submission on the App StoreNote that if you need it work for iPads, You need to add these icon declarations in `CFBundleIcons~ipad` as well. [See here](https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/uid/TP40009249-SW14) for more details.
Here is my `Info.plist` after adding Alternate Icons
#### Screenshot![info.plist](https://raw.githubusercontent.com/tastelessjolt/flutter_dynamic_icon/master/imgs/info-plist.png)
#### Raw
```xmlCFBundleDevelopmentRegion
en
CFBundleExecutable
$(EXECUTABLE_NAME)
CFBundleIcons
CFBundleAlternateIcons
chills
CFBundleIconFiles
chills
UIPrerenderedIcon
photos
CFBundleIconFiles
photos
UIPrerenderedIcon
teamfortress
CFBundleIconFiles
teamfortress
UIPrerenderedIcon
CFBundlePrimaryIcon
CFBundleIconFiles
chills
UIPrerenderedIcon
CFBundleIdentifier
$(PRODUCT_BUNDLE_IDENTIFIER)
CFBundleInfoDictionaryVersion
6.0
CFBundleName
flutter_dynamic_icon_example
CFBundlePackageType
APPL
CFBundleShortVersionString
$(FLUTTER_BUILD_NAME)
CFBundleSignature
????
CFBundleVersion
$(FLUTTER_BUILD_NUMBER)
LSRequiresIPhoneOS
UILaunchStoryboardName
LaunchScreen
UIMainStoryboardFile
Main
UISupportedInterfaceOrientations
UIInterfaceOrientationPortrait
UIInterfaceOrientationLandscapeLeft
UIInterfaceOrientationLandscapeRight
UISupportedInterfaceOrientations~ipad
UIInterfaceOrientationPortrait
UIInterfaceOrientationPortraitUpsideDown
UIInterfaceOrientationLandscapeLeft
UIInterfaceOrientationLandscapeRight
UIViewControllerBasedStatusBarAppearance
```
Now, you can call `FlutterDynamicIcon.setAlternateIconName` with the `CFBundleAlternateIcons` key as the argument to set that icon.
### Dart/Flutter Integration
From your Dart code, you need to import the plugin and use it's static methods:
```dart
import 'package:flutter_dynamic_icon/flutter_dynamic_icon.dart';try {
if (await FlutterDynamicIcon.supportsAlternateIcons) {
await FlutterDynamicIcon.setAlternateIconName("photos");
print("App icon change successful");
return;
}
} on PlatformException {} catch (e) {}
print("Failed to change app icon");...
// set batch number
try {
await FlutterDynamicIcon.setApplicationIconBadgeNumber(9399);
} on PlatformException {} catch (e) {}// gets currently set batch number
int batchNumber = FlutterDynamicIcon.getApplicationIconBadgeNumber();```
Check out the `example` app for more details
## Screenrecord
## Showing App Icon change
![Screenrecording of the example](https://raw.githubusercontent.com/tastelessjolt/flutter_dynamic_icon/master/imgs/screen.gif)## Showing Batch number on app icon change in SpringBoard
![Screenrecording of the example](https://raw.githubusercontent.com/tastelessjolt/flutter_dynamic_icon/master/imgs/batch.gif)## Reference
This was made possible because this blog. I borrowed a lot of words from this blog.
https://medium.com/ios-os-x-development/dynamically-change-the-app-icon-7d4bece820d2