Skip to content

flet build: deterministic, decodable icon/splash image selection - #6707

Merged
FeodorFitsner merged 2 commits into
mainfrom
feature/icon-format-selection
Jul 25, 2026
Merged

flet build: deterministic, decodable icon/splash image selection#6707
FeodorFitsner merged 2 commits into
mainfrom
feature/icon-format-selection

Conversation

@FeodorFitsner

@FeodorFitsner FeodorFitsner commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Problem

flet build could crash with a machine-dependent NoDecoderForImageFormatException from flutter_launcher_icons. When an app's assets/ held several files sharing a base name — e.g. both icon.png and icon.svgfind_platform_image selected images[0] from glob.glob(...), whose order is filesystem-dependent. So the same app could pick icon.png on one machine and icon.svg on another. SVG is vector and can't be decoded by the raster icon/splash generators (flutter_launcher_icons, flutter_native_splash), turning a working build into a crash purely based on directory-listing order.

This showed up in the wild: an app that built fine locally failed on a fresh CI/cloud builder, both with the identical assets/icon.png + assets/icon.svg.

Fix

In find_platform_image:

  • Filter to decodable formats. .svg is dropped everywhere (never decodable); .icns stays macOS-only and .ico Windows-only (unchanged).
  • Rank deterministically. Remaining candidates are sorted so a raster image wins in a fixed order (.png first), independent of glob/filesystem order — so icon.png always beats icon.svg when both exist.
  • Graceful SVG-only fallback. When the only candidate is an SVG (no raster sibling), it's skipped with a build-log warning and None is returned, so fallback_image leaves the template default in place and the default Flet icon is used instead of crashing.

Applies to both icons and splash images (both generators are raster-only).

Tests

Adds tests/test_find_platform_image.py (5 cases): raster-over-SVG preference, .png ranked over other raster, SVG-only → None + warning, no-candidates → silent None, and .ico being Windows-only.

Targets the 0.86.3 milestone.

Summary by Sourcery

Ensure flet build deterministically selects decodable raster icons/splash images per platform to avoid crashes when multiple formats share a base name.

Bug Fixes:

  • Filter candidate icon/splash images to formats the underlying Flutter generators can decode, excluding SVGs and platform-incompatible .ico/.icns files.
  • Rank remaining image candidates by raster format priority so .png and other supported raster images are chosen deterministically regardless of filesystem order.
  • Gracefully handle SVG-only and other incompatible image cases by falling back to the default icon with a logged warning instead of crashing.

Documentation:

  • Document the icon/splash image selection fix and its impact in the 0.86.3 changelog entry.

Tests:

  • Add unit tests covering deterministic image selection across mixed formats, SVG-only fallback behavior, absence of candidates, and platform-specific handling of .ico files.

find_platform_image picked the first glob.glob() match when multiple files
shared a base name (e.g. icon.png + icon.svg). glob order is
filesystem-dependent, so the same app could pick icon.png on one machine
and icon.svg on another; SVG can't be decoded by flutter_launcher_icons /
flutter_native_splash, so it crashed with NoDecoderForImageFormatException.

Now filter to decodable formats (.svg dropped everywhere; .icns macOS-only,
.ico Windows-only) and rank so a raster image (.png first) always wins,
making the choice deterministic. When only an SVG is supplied, skip it with
a build-log warning and fall back to the default icon instead of crashing.

@sourcery-ai sourcery-ai Bot left a comment

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.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying flet-website-v2 with  Cloudflare Pages  Cloudflare Pages

Latest commit: 53d053a
Status: ✅  Deploy successful!
Preview URL: https://a8d2cd16.flet-website-v2.pages.dev
Branch Preview URL: https://feature-icon-format-selectio.flet-website-v2.pages.dev

View logs

@FeodorFitsner
FeodorFitsner merged commit fca8295 into main Jul 25, 2026
24 of 166 checks passed
@FeodorFitsner
FeodorFitsner deleted the feature/icon-format-selection branch July 25, 2026 20:24
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.

1 participant