Flutter: flavors launcher icons made simple
Published: 2021-01-11 08:43:14

Anyone that has already dealt with [flavors in Flutter](https://flutter.dev/docs/deployment/flavors) knows that they are not such an easy thing to implement. 

You usually end up reading a lot of articles, going back and forth between your favorite IDE and Xcode, looking at configuration in your `build.gradle` and then crying over Xcode build configs...

But one thing is pretty easy to do when using flavors : generating appropriate launcher icons for both platforms, for all resolutions and obviously each flavor.

Supposing we have development, integration and production flavor, what we want to do in the end is have all these icons for Android:

![flutter-flavor-android](https://dev-to-uploads.s3.amazonaws.com/i/kawu4aztn74fqsjybols.jpg)

And the same goes for iOS:
![flutter-flavor-ios](https://dev-to-uploads.s3.amazonaws.com/i/fyy57un632u8qrnnkx66.jpg)

I don't know about you, but I really don't want to generate all these icons by hand... so we will instead use the great [Flutter plugin flutter_launcher_icons](https://pub.dev/packages/flutter_launcher_icons) !

As it is just a generator that we will use once, we don't need it at runtime so we can add it to our `pubspec.yaml` `dev_dependencies`:

```yaml
dev_dependencies:
  ...
  flutter_launcher_icons: ^0.8.1
```

Now we will need to configure the assets location for each flavor:

**`flutter_launcher_icons-development.yaml`**:

```yaml
flutter_icons:
  android: true
  ios: true
  image_path: "assets/launcher_icon/launcher-icon-dev.png"
```

**`flutter_launcher_icons-integration.yaml`**:

```yaml
flutter_icons:
  android: true
  ios: true
  image_path: "assets/launcher_icon/launcher-icon-int.png"
```

**`flutter_launcher_icons-production.yaml`**:

```yaml
flutter_icons:
  android: true
  ios: true
  image_path: "assets/launcher_icon/launcher-icon-prod.png"
```

Now that we have our plugin configured for each flavor, it's time to add our actual icons in our assets:

![Capture d’écran 2021-01-08 à 16.18.17](https://dev-to-uploads.s3.amazonaws.com/i/4ydx9yhlbv1w7huj59aj.png)

As you probably understood already, the next step will generate all the icons shapes and resolutions as needed by each platform. This process will take our source icon for each flavor and will downscale it to create all resolutions. This is important because it means you should provide the highest resolution of 1024x1024 for source icons. 

**Note**: at this point our assets are not related to anything, i.e. not used by either Android or iOS, so we need to translate them in their respective format:

Let's do just that by invoking a run of our plugin:

```shell
flutter pub get
flutter pub run flutter_launcher_icons:main -f flutter_launcher_icons*
```

After a few seconds, you should get a result similar to this one:

```shell
════════════════════════════════════════════
   FLUTTER LAUNCHER ICONS (v0.8.0)
════════════════════════════════════════════

Flavor: development
• Creating default icons Android
• Overwriting the default Android launcher icon with a new icon
• Building iOS launcher icon for development

Flavor: integration
• Creating default icons Android
• Overwriting the default Android launcher icon with a new icon
• Building iOS launcher icon for integration

Flavor: production
• Creating default icons Android
• Overwriting the default Android launcher icon with a new icon
• Building iOS launcher icon for production

✓ Successfully generated launcher icons for flavors
```

And voilà, you now have brand new icons for all platforms, flavors and resolutions conbinations. 

Pretty neat, right ?

As a side note, the plugin is also able to generate [adaptative Android icons](https://developer.android.com/guide/practices/ui_guidelines/icon_design_adaptive) by providing `adaptive_icon_background` and `adaptive_icon_foreground` for Android, which I highly recommend !

---
### References

* [flutter_launcher_icons plugin](https://pub.dev/packages/flutter_launcher_icons)
* [Android adaptative icons](https://developer.android.com/guide/practices/ui_guidelines/icon_design_adaptive) and [how to create them](https://developer.android.com/studio/write/image-asset-studio)
* [iOS app icons](https://developer.apple.com/design/human-interface-guidelines/ios/icons-and-images/app-icon/)
* [Creating flavors of a Flutter app](https://cogitas.net/creating-flavors-of-a-flutter-app/)
* [Flavoring Flutter](https://medium.com/@salvatoregiordanoo/flavoring-flutter-392aaa875f36)
* [Flutter Ready to Go](https://medium.com/flutter-community/flutter-ready-to-go-e59873f9d7de)
* [No more Flavors, no more iOS Schemas. Command argument that changes everything](https://itnext.io/flutter-1-17-no-more-flavors-no-more-ios-schemas-command-argument-that-solves-everything-8b145ed4285d)