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
Localizing Dynamic Content in Flutter: A Guide to Backend-Driven Translations
Many Flutter apps need to display content that changes based on user locale, but also comes from a backend (like Firebase). This post will explore best practices for fetching and integrating dynamic, localized content from a backend, ensuring a seamless user experience across different languages and regions without hardcoding translations.
Unraveling Type Mismatch Errors in Flutter: A Guide to 'X can't be assigned to Y' and '_InternalLinkedHashMap' Issues
Developers frequently encounter cryptic type mismatch errors like 'The argument type X can't be assigned to the parameter type Y' or '_InternalLinkedHashMap has no instance method 'cast''. This post will demystify these common Flutter/Dart type errors, explain their root causes (e.g., conflicting imports, dynamic typing pitfalls, JSON deserialization issues), and provide practical solutions to diagnose and fix them, improving code robustness and reducing debugging time.
Solving Flutter Web Memory Leaks: A Practical Guide to Identifying and Fixing Performance Issues
Flutter Web applications can suffer from increasing memory usage over time, leading to performance degradation. This post will delve into common causes of memory leaks in Flutter Web, provide practical debugging techniques using browser developer tools and Dart DevTools, and offer actionable strategies to identify and fix these issues for a smoother user experience.