Skip to content

fix: select platform-compatible icon format in find_platform_image#6381

Open
HG-ha wants to merge 3 commits intoflet-dev:mainfrom
HG-ha:fix/platform-icon-selection
Open

fix: select platform-compatible icon format in find_platform_image#6381
HG-ha wants to merge 3 commits intoflet-dev:mainfrom
HG-ha:fix/platform-icon-selection

Conversation

@HG-ha
Copy link
Copy Markdown

@HG-ha HG-ha commented Apr 5, 2026

Summary

find_platform_image uses glob.glob to match icon files by base name, then blindly picks images[0]. On NTFS the alphabetical ordering causes .icns (macOS-only) to be selected over .ico/.png when building for Windows, making flutter_launcher_icons fail with NoDecoderForImageFormatException.

This PR introduces a per-platform preferred extension list so that the most appropriate format is selected for each build target:

  • Windows: .ico > .png > others
  • macOS: .icns > .png > others
  • Linux/Web/Android/iOS: .png > others

Unrecognized extensions still sort last, so existing setups with only .png files are completely unaffected.

How to reproduce

  1. Place icon.icns, icon.ico, and icon.png in src/assets/
  2. Run flet build windows -v
  3. Build fails:
    Found "icon" image at ...\icon.icns
    ✗ ERROR: NoDecoderForImageFormatException
    images/icon.icns
    

Changes

  • sdk/python/packages/flet-cli/src/flet_cli/commands/build_base.py:
    • Added _PLATFORM_IMAGE_PREFERENCE class variable mapping each target platform to a ranked list of preferred image extensions
    • Modified find_platform_image to sort glob results by platform preference before selecting the best match

Summary by Sourcery

Bug Fixes:

  • Fix selection of incompatible .icns icons on non-macOS targets by choosing the most appropriate image format per platform when multiple files share the same base name.

find_platform_image uses glob.glob to match icon files by base name, then blindly picks images[0]. On NTFS the alphabetical ordering causes .icns (macOS-only) to be selected over .ico/.png when building for Windows, which makes flutter_launcher_icons fail with NoDecoderForImageFormatException.

Introduce a per-platform preference list so the method picks the most appropriate format for the target: .ico first on Windows, .icns first on macOS, .png as universal fallback everywhere.

Made-with: Cursor
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 5, 2026

CLA assistant check
All committers have signed the CLA.

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've reviewed this pull request using the Sourcery rules engine

Find first matching image file by base name and queue it for copy.
Find the best matching image file for the current target platform.

When multiple files share the same base name (e.g. ``icon.icns``,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Can you remove all double ticks "``" in comments please?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, removed all double backticks. Thanks for the review!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:) Well, you removed all ticks, not replaced them with a single ticks. It's fine, it's a known issue with Claude/Codex. Put single ticks back please.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I now understand your meaning. The correction has been made.

@FeodorFitsner
Copy link
Copy Markdown
Contributor

Your PR adds .svg and .bmp to the matrix which are not supported by flutter_launcher_icons package. I'd trim these lists to only what lutter_launcher_icons actually decodes.

Also, there is an alternative, simpler approach: Instead of a full preference dict, you could just exclude known-incompatible extensions per platform (e.g. strip .icns on non-macOS, strip .ico on non-Windows) and keep the existing "pick first" behavior. That's a smaller change and addresses the actual bug without introducing a ranking system the project then has to maintain. What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants