To change the application launcher icon in a Flutter app, you typically need to replace the default icons with your custom ones. Here’s a step-by-step guide on how to do this:
For Android:
- Prepare Your Icons: Create your custom icons in the required sizes. For Android, you typically need icons in different densities. Common densities include mdpi, hdpi, xhdpi, xxhdpi, and xxxhdpi.
- Replace the Icons: Replace the default icons with your custom ones in the following directories of your Flutter project:
android/app/src/main/res/mipmap-mdpiandroid/app/src/main/res/mipmap-hdpiandroid/app/src/main/res/mipmap-xhdpiandroid/app/src/main/res/mipmap-xxhdpiandroid/app/src/main/res/mipmap-xxxhdpi
ic_launcher.pngfiles in each of these directories with your custom icons. - Update AndroidManifest.xml: Open
android/app/src/main/AndroidManifest.xmland make sure theandroid:iconattribute of the<application>tag points to your custom launcher icon.
For iOS:
- Prepare Your Icons: Create your custom icons in the required sizes. For iOS, you typically need icons in different resolutions for various devices and purposes. You’ll often provide icons for iPhone, iPad, App Store, etc.
- Replace the Icons: Replace the default icons with your custom ones in the
ios/Runner/Assets.xcassets/AppIcon.appiconsetdirectory of your Flutter project. - Update Info.plist: Open
ios/Runner/Info.plistand make sure theCFBundleIconNamekey in this file matches the name of your custom icon file without the extension. For example, if your custom icon file is namedAppIcon.png, then the value ofCFBundleIconNameshould beAppIcon.
Using Tools:
There are also tools available to help automate this process, such as the flutter_launcher_icons package. This package allows you to define your icons in the pubspec.yaml file and automatically generates the required configuration for both Android and iOS.
Example flutter_launcher_icons Configuration:
Add the following lines to your pubspec.yaml file:
dev_dependencies:
flutter_launcher_icons: ^0.9.2
flutter_icons:
android: true
ios: true
image_path: "assets/icon/app_icon.png"
Replace "assets/icon/app_icon.png" with the path to your custom icon.
After adding this configuration, run the following command in your terminal:
flutter pub get
flutter pub run flutter_launcher_icons:main
This will generate the necessary icon files and configurations for both Android and iOS according to the specified image path.
Choose the method that best fits your workflow and project requirements.