flutter_launcher_icons

repository·master·Indexed 24 days ago

https://github.com/fluttercommunity/flutter_launcher_icons

A command-line tool that simplifies updating launcher icons for Flutter applications across Android, iOS, Web, Windows, and MacOS. It supports automatic configuration generation, flavor-specific icons, and platform-specific attributes such as Android adaptive icons and iOS 18+ dark/tinted modes.

Tokens
4.8K
Snippets
8
Records
35
Agent score
84%

What's inside flutter_launcher_icons

  1. Use Flavor support for launcher icons

    master

    To support multiple flavors, create a specific configuration file for each flavor using the naming convention flutter_launcher_icons-<flavor>.yaml.

    For example, if you have a flavor named production, create flutter_launcher_icons-production.yaml. The configuration format remains the same as the standard config.

  2. Setup the Flutter Launcher Icons configuration file

    master

    You can configure launcher icons in two ways:

    1. Automatic Generation: Run the following command to create a default flutter_launcher_icons.yaml file in your project root:

      dart run flutter_launcher_icons:generate
      • Use -f <filename> to specify a custom name or location.
      • Use -o to override an existing configuration file.
    2. Manual Configuration: Add a flutter_launcher_icons section to your pubspec.yaml or create a standalone .yaml file.

    Note: If using a custom filename, ensure the file is in the same directory as your pubspec.yaml.

    dev_dependencies:
      flutter_launcher_icons: "^0.14.4"
    
    flutter_launcher_icons:
      android: "launcher_icon"
      ios: true
      image_path: "assets/icon/icon.png"
      min_sdk_android: 21
      web:
        generate: true
        image_path: "path/to/image.png"
        background_color: "#hexcode"
        theme_color: "#hexcode"
      windows:
        generate: true
        image_path: "path/to/image.png"
        icon_size: 48
      macos:
        generate: true
        image_path: "path/to/image.png"
  3. Run the Flutter Launcher Icons package

    master

    Once your configuration is set up, execute the following commands to generate the icons:

    1. Fetch dependencies:
      flutter pub get
    2. Run the generator:
      dart run flutter_launcher_icons

    If you are using a custom configuration file name (other than flutter_launcher_icons.yaml or pubspec.yaml), you must specify it using the -f flag:

    dart run flutter_launcher_icons -f <your config file name here>
    flutter pub get
    dart run flutter_launcher_icons
  4. How icon generation is orchestrated via generateIconsFor

    master

    The generateIconsFor function is the central orchestrator for the icon generation process. It accepts a configuration object, optional flavor, a prefix path, a logger, and a callback function that returns a list of IconGenerator instances based on an IconGeneratorContext.

    Lifecycle of generation:

    1. Context Creation: An IconGeneratorContext is initialized with the provided config, logger, prefix, and flavor.
    2. Platform Discovery: The platforms callback is executed using the context to determine which platforms (e.g., Web, Windows, macOS) need processing.
    3. Validation: For each platform, validateRequirements() is called. If it returns false, the platform is skipped.
    4. Execution: If requirements are met, createIcons() is called asynchronously to perform the actual file generation.
    5. Error Isolation: If a specific platform fails during validation or creation, the error is logged, but the process continues to the next platform in the list.
  5. How flavor-specific configurations are detected

    master

    The tool supports multiple app flavors by scanning the current directory for configuration files following a specific naming convention.

    If the tool finds files matching the regex ^flutter_launcher_icons-(.*).yaml$, it treats the captured group as a flavor name. For each detected flavor, it attempts to load a configuration using Config.loadConfigFromFlavor(flavor, prefixPath).

    Example: A file named flutter_launcher_icons-dev.yaml will be treated as the configuration for the dev flavor.

  6. Configure iOS launcher icons

    master

    Use the ios key to define iOS icon behavior:

    • true: Overwrites the default Flutter launcher icon.
    • false: Skips icon generation for iOS.
    • icon/path/here.png: Generates a new icon with the specified name without removing the existing default icon.

    iOS Specific Attributes:

    • image_path_ios: Path to a specific icon for iOS (defaults to image_path).
    • remove_alpha_ios: Removes the alpha channel from icons.
    • background_color_ios: Color ("#RRGGBB") used when remove_alpha_ios is true (default: "#ffffff").
    • image_path_ios_dark_transparent: Path to the dark mode icon for iOS 18+ (recommended to be transparent).
    • image_path_ios_tinted_grayscale: Path to the tinted mode icon for iOS 18+ (should be a grayscale image).
    • desaturate_tinted_to_grayscale_ios: If true, automatically desaturates the provided tinted mode icon to grayscale (default: false).

    Note: iOS icons should fill the entire image and not contain transparent borders.

  7. Configure Android launcher icons

    master

    Use the android key to define Android icon behavior:

    • true: Overwrites the default Flutter launcher icon.
    • false: Skips icon generation for Android.
    • icon/path/here.png: Generates a new icon with the specified name without removing the existing default icon.

    Android Specific Attributes:

    • image_path_android: Path to a specific icon for Android (defaults to image_path).
    • min_sdk_android: Minimum Android SDK (default: 21).
    • adaptive_icon_background: Color ("#ffffff") or image asset for the adaptive icon background.
    • adaptive_icon_foreground: Image asset for the adaptive icon foreground. Note: Adaptive icons are only generated if both background and foreground are provided.
    • adaptive_icon_foreground_inset: Padding percentage for the foreground (default: 16).
    • adaptive_icon_monochrome: Image asset for Android 13+ themed icons.
  8. Configure Web, Windows, and MacOS launcher icons

    master

    Web

    Under the web key:

    • generate: Boolean to enable/disable generation.
    • image_path: Path to the web icon.
    • background_color: Updates background_color in web/manifest.json.
    • theme_color: Updates theme_color in web/manifest.json.

    Windows

    Under the windows key:

    • generate: Boolean to enable/disable generation.
    • image_path: Path to the Windows icon.
    • icon_size: Icon size (must be between 48 and 256, default: 48).

    MacOS

    Under the macos key:

    • generate: Boolean to enable/disable generation.
    • image_path: Path to the MacOS icon.
  9. Accessing configuration and CLI flags via IconGeneratorContext

    master

    When implementing or interacting with an IconGenerator, the IconGeneratorContext provides a unified way to access user-provided settings and CLI arguments:

    • config: The full Config object parsed from the configuration file.
    • logger: The FLILogger instance for reporting progress and errors.
    • prefixPath: The value passed via the --prefix CLI flag.
    • flavor: The value passed via the --flavor CLI flag (optional).

    Platform-specific configuration shortcuts:

    • webConfig: Accesses WebConfig settings.
    • windowsConfig: Accesses WindowsConfig settings.
    • macOSConfig: Accesses MacOSConfig settings.