Mastering App Icons in Flutter: A Guide to `flutter_launcher_icons` and Beyond
The Flutter news you actually need
No spam, ever. Unsubscribe in one click.
Your app icon is the first thing users see—it’s your digital storefront sign. But if you’ve ever tried to manage icons for both Android and iOS in Flutter, you know it can be a frustrating process of resizing, renaming, and placing files in multiple directories. Doing this manually is error-prone and time-consuming.
Thankfully, the Flutter community has a great solution: the flutter_launcher_icons package. This guide will walk you through using this tool and understanding app icon requirements on both platforms.
The Problem: A Multi-Platform Icon Nightmare
Android and iOS have different requirements for app icons. They need different file names, sizes, and folder structures.
- Android primarily uses
mipmap-folders (hdpi, mdpi, xhdpi, etc.) and expects specific filenames likeic_launcher.png. - iOS uses an
Assets.xcassetsapp icon set with specific sizes for the app, notifications, and settings.
Manually creating and updating dozens of image files isn’t scalable. This is where automation helps.
Introducing flutter_launcher_icons
flutter_launcher_icons is a command-line tool that automates icon generation. You provide one high-resolution source image, and it generates all the correctly sized and named variants for Android and iOS.
Step 1: Setup and Configuration
First, add the package to your pubspec.yaml under dev_dependencies.
dev_dependencies:
flutter_launcher_icons: ^0.13.1
Next, add a flutter_launcher_icons configuration section in the same file.
flutter_launcher_icons:
android: true
ios: true
image_path: "assets/icons/app_icon.png"
image_path_android: "assets/icons/android_icon.png" # Optional override
image_path_ios: "assets/icons/ios_icon.png" # Optional override
# Optional: Remove background for adaptive icons (Android 8.0+)
android_adaptive_icon_foreground: "assets/icons/adaptive_foreground.png"
android_adaptive_icon_background: "assets/icons/adaptive_background.png"
Step 2: Preparing Your Source Image
Your source image should be:
- High resolution: At least 1024x1024 pixels.
- Simple and recognizable: Icons are small. Avoid fine detail.
- Square: The tool requires a square image.
- Without transparency for Android (usually): Android’s legacy launcher icons typically use a solid background. Use the adaptive icon settings if you want transparency.
Step 3: Generating the Icons
Run the package from your terminal:
flutter pub get
flutter pub run flutter_launcher_icons:main
The package will:
- Process your source image.
- Generate all Android variants and place them in
android/app/src/main/res/mipmap-*/. - Generate the iOS icon set and integrate it into your
ios/Runner/Assets.xcassets/AppIcon.appiconset.
Step 4: Verifying and Building
Always verify the output:
- Android: Check the
mipmapfolders inandroid/app/src/main/res/. - iOS: Open your project in Xcode (
open ios/Runner.xcworkspace), navigate toRunner > Assets.xcassets > AppIcon, and ensure all slots are filled.
Finally, do a clean rebuild:
flutter clean
flutter run
Common Pitfalls and How to Avoid Them
-
“My icon looks blurry on one platform!”
- Cause: You likely provided a source image that was too small. The tool scales it up for the largest required size, causing pixelation.
- Fix: Always start with an image that is larger than the largest required icon size (1024x1024 for iOS).
-
“The command runs but nothing changes!”
- Cause: Cached icons.
- Fix: Always run
flutter cleanafter generating new icons. For iOS, you may also need to delete the app from your simulator/device and rebuild.
-
“I get an error about the image path!”
- Cause: The
image_pathin your config doesn’t point to a valid file, or the file isn’t square. - Fix: Double-check the path relative to your project root. Confirm the image is square.
- Cause: The
-
“iOS icons are generated but don’t show up in Xcode!”
- Cause: This sometimes happens if the
Contents.jsonfile becomes corrupted. - Fix: In Xcode, right-click the AppIcon set and select “Delete”. Re-run
flutter pub run flutter_launcher_icons:main.
- Cause: This sometimes happens if the
Going Beyond: Adaptive and Custom Icons
Android Adaptive Icons
For Android 8.0 (API 26) and above, you can create adaptive icons with separate foreground and background layers. Configure them using the android_adaptive_icon_foreground and android_adaptive_icon_background settings.
Handling iOS Complications
While flutter_launcher_icons handles the standard app icon, remember that iOS also uses icons for Spotlight search, Settings, and Notifications. The package manages these automatically. However, if you need to set a different icon for iPad or macOS, you’ll need to manually add additional icon sets in Xcode.
Best Practices for a Polished Workflow
- Version Control: Add the generated native directories to your
.gitignore. Only commit your sourceassets/icons/app_icon.pngand yourpubspec.yamlconfiguration. - Design First: Finalize your app icon design early.
- Test on Real Devices: Icons can look different on various device screens and launchers.
By integrating flutter_launcher_icons into your workflow, you turn a tedious process into a single command. This lets you focus on building your app.
This blog is produced with the assistance of AI by a human editor. Learn more
Related Posts
Optimizing Flutter UI Performance: Best Practices for Date Formatting and Expensive Operations
Developers often face performance bottlenecks when performing expensive operations like date formatting directly within Flutter's `build` method, especially in fast-scrolling lists. This post will delve into common pitfalls, explain why these operations are costly, and provide practical strategies for optimizing UI performance by caching formatters, using `initState`, and leveraging `compute` for background processing without blocking the UI.
Optimizing Your Flutter Dev Setup: IDEs, Simulators, and AI Tools for Peak Productivity
Flutter developers frequently seek to refine their development environments. This post will dive into popular IDE choices like VS Code and Android Studio, discuss best practices for managing iOS and Android simulators (including in-IDE options), and explore the practical integration of AI tools for code generation and problem-solving to boost overall efficiency.
Demystifying Flutter Performance: Practical Strategies for Large-Scale Apps
Flutter's performance is often blamed for issues in complex applications, but the real culprits are usually architectural decisions, inefficient widget rebuilds, and unoptimized resource handling. This post will dive into common performance bottlenecks in large Flutter apps, providing actionable strategies for profiling, optimizing state management, handling images and network requests efficiently, and leveraging CI/CD for continuous performance monitoring.