oversized_assets
Reports a declared image file larger than the size limit for its resolution. Compress it, or store it in a smaller format.
- Kind
- asset check (reports only)
- Tier
- advisory
- Host
- command-line program only (
assay assets) - Fix
- none
What it reports
Section titled “What it reports”A declared image file of the package that is larger than the limit for its resolution: the photograph exported straight from the camera, the GIF of forty frames, the 3.0x icon saved without compression.
| Resolution | Default limit |
|---|---|
| 1.0x (the base file) | 500 kB |
| 2.0x | 1000 kB |
| 3.0x | 1500 kB |
- Every image file is judged on its own: the base file and each resolution variant, against the limit of its own resolution.
- A resolution the limits do not name takes the limit of the nearest lower one: a 1.5x variant takes the 500 kB of 1.0x.
- One kilobyte is 1,000 bytes. A file exactly at its limit is not over it.
- By default, an image is a file whose extension is
png,jpg,jpeg,gif,webp,bmporwbmp, in any case. Any other file is never a result, however large. - A publishable package is judged too: its images are bundled into every app that uses it.
The message names the size, the resolution and the limit: “The 1.0x image is 612.34 kB, over its limit of 500 kB.”
The asset checks only report: no result enters the gate or the baseline, and none fails a command.
Every declared asset is bundled into every build of the app. An image several times larger than it needs to be costs download size and memory for every user, and it is seldom noticed until release, when the bundle has grown and nobody knows by what. An agent that adds an image you supplied, or one it generated, has no reason to look at its size.
The check is advisory because a large image can be what you want (a full-screen photograph, an animation), and only you can say so.
Configuration
Section titled “Configuration”Under the assay: key of the project’s root analysis_options.yaml. The check is on under every preset.
| Key | Default | Effect |
|---|---|---|
assay.assets.oversized_assets.enabled |
true |
false switches the check off. The short form oversized_assets: false means the same. |
assay.assets.oversized_assets.exclude |
[] |
Path globs where the check places no result. |
assay.assets.oversized_assets.max_kb |
{1.0x: 500, 2.0x: 1000, 3.0x: 1500} |
The limit in kilobytes of 1,000 bytes, by resolution. |
assay.assets.oversized_assets.image_extensions |
[png, jpg, jpeg, gif, webp, bmp, wbmp] |
The extensions of the files that are images, without the dot. |
assay: assets: oversized_assets: max_kb: {3.0x: 2000}Your max_kb is laid over the default, resolution by resolution: this one changes only 3.0x, and 1.0x stays at 500 and 2.0x at 1000. Your image_extensions replaces the default as a whole.
Running it
Section titled “Running it”assay assets # every asset checkassay assets oversized_assets # this one aloneIt reads no Dart file. The check does not run in the editor, in assay check, in assay cross-file or in the gate. See assay assets.
Suppressing it
Section titled “Suppressing it”A suppression comment cannot silence the result, since an asset has no line to write it on. Use the check’s exclude for an image that is large on purpose.
Details
Section titled “Details”All cases
The message and the result
Section titled “The message and the result”- Where the limit is that of a lower resolution: “The 1.5x image is 500.001 kB, over its limit of 500 kB, the one of 1.0x.”
- The size is exact, in kilobytes of 1,000 bytes, with up to three decimals. The size and the limit are in the same unit.
- The how-to-fix line is “Compress the image or store it in a smaller format; if it must stay this large, raise max_kb for its resolution or add its path to the check’s exclude.”
- A variant that is too large is a result at its own path (
assets/icons/3.0x/logo.png), beside a base file that is not. A base file and a variant that are both too large are two results. A variant without its base file is judged like any other. - The result is a violation with the source
assets, the ruleoversized_assetsand the advisory tier. It is of the file as a whole, at line 1, column 1, with no extent. Its fingerprint is the check’s name, the file’s path and an empty line text: a file whose size changes and stays over the limit keeps its fingerprint, and a file that is moved or renamed becomes a new result.
The limit
Section titled “The limit”The limit grows with the resolution: a 2.0x variant holds four times the pixels of its 1.0x base, a 3.0x variant nine times. The limit lets each be larger than the base, without letting it be as large as its pixels would allow.
One kilobyte is 1,000 bytes. A file exactly at its limit is not over it: under the default, a base file of 500,000 bytes is no result, one of 500,001 bytes is.
A resolution the limits do not name takes the limit of the nearest lower one they name. Under the default, a 1.5x variant takes the limit of 1.0x (500 kB), a 2.625x variant that of 2.0x, and a 4.0x variant that of 3.0x (1500 kB). A resolution below all of them, such as 0.75x, takes the limit of the lowest.
The base file is 1.0x. A variant’s resolution is the one its directory name gives (2.0x/, 2x/, 1.5x/), read as the asset inventory reads it: see Which files count as declared assets.
Which files are images
Section titled “Which files are images”A declared file is an image when its extension is in image_extensions, compared without regard to case. The default is png, jpg, jpeg, gif, webp, bmp and wbmp, the formats Flutter’s image codecs decode. logo.PNG and photo.Jpeg are images, and Android’s .9.png files are images by their last extension. Any other declared file (a video, a font declared as an asset, a JSON file, an SVG) is never a result, however large. Fonts, shaders and deferred components are not under flutter: assets:, and are not read.
The size is the file’s size on disk. No image is decoded, so the check says nothing of its pixels, of whether it has more pixels than any screen needs, or of whether it could be stored smaller.
The two package types
Section titled “The two package types”Both are judged. A publishable package’s oversized image is bundled into every app that uses it, and is reported like an application’s. (unused_assets, by contrast, says nothing in a publishable package.)
Only the package at the project root is judged: not the assets of a nested package, such as an example/ app or a package of a pub workspace. An entry packages/<another package>/… declares another package’s asset, which is never judged.
Where no result is placed
Section titled “Where no result is placed”- At a file that
assay.excludeoranalyzer.excludecovers. - At a file that the check’s own
excludecovers.
The globs are read from the project root, like a rule’s exclude, and match the file the result would be placed at: the base file, or the variant. assets/photos/** covers both.
How max_kb is written
Section titled “How max_kb is written”A map from a resolution to a whole number above zero. A resolution is written as Flutter names a resolution directory: a number, perhaps with a decimal point, followed by x and nothing else: 1.0x, 2x, 1.5x, 3.x. 2x and 2.0x are the same resolution, and config prints each as 2.0x.
Your map is laid over the default, resolution by resolution. The resolutions it names take its limits, and the others keep the default’s:
max_kb: {3.0x: 2000}changes only 3.0x; 1.0x stays at 500 and 2.0x at 1000.max_kb: {2x: 1200}changes only 2.0x.- A resolution the default does not name, such as
4.0x: 2500, is added, and variants of 4.0x and above take it. - Along an
include:chain, each options file lays its map over what the files before it set: an included{2.0x: 800}and the project’s{3.0x: 2000}together are{1.0x: 500, 2.0x: 800, 3.0x: 2000}. - A resolution can be changed, not removed.
This is the one parameter laid over its default part by part. Every other one, image_extensions among them, replaces its default as a whole.
These are configuration errors, each reported with the file and the key. While the configuration is in error, no asset check runs:
- a
max_kbthat is not a map, such asmax_kb: 500; - a key that is not a resolution as above, such as
2.0,2.0X,@2xor0x; - a resolution written twice, such as
2xand2.0x; - a value that is not a whole number above zero, such as
0,-1,1.5or"500"; - an empty map.
The message says what is expected: “The value has the wrong type: expected a map from a resolution, such as 2.0x, to a whole number above zero.”
How image_extensions is written
Section titled “How image_extensions is written”A list of extensions without the dot, each of letters, digits, _, + and -. Your list replaces the default as a whole:
assay: assets: oversized_assets: image_extensions: [png, jpg, jpeg, webp] # GIF animations are judged elsewhere exclude: - assets/backgrounds/** # full-screen photographs, on purposeAn entry with a dot (.png, tar.gz), an empty one, one that is not text, or a value that is not a list is a configuration error: “The value has the wrong type: expected a list of file extensions without the dot, such as png.”
missing_asset_variants has the same key with the same default; each check has its own value.
What assay config shows
Section titled “What assay config shows”assay config prints the asset checks where the project changed one, with each key not at its default, and max_kb as it is in effect, laid over the default. assay config --verbose prints every key of every check with the file its value came from, and each resolution of max_kb on a row of its own. For the project with max_kb: {3.0x: 2000}:
╭─ Asset checks ──────────────────────────────────────────────── 3 on · 0 off ─╮│ Key Value Set in ││ ────────────────────────────────────────────────────────────────────────── ││ ● unused_assets ││ exclude [] default ││ ● oversized_assets ││ exclude [] default ││ max_kb 1.0x: 500 default ││ 2.0x: 1000 default ││ 3.0x: 2000 analysis_options.yaml ││ image_extensions ["png","jpg","jpeg","gif","webp", default ││ "bmp","wbmp"] ││ ● missing_asset_variants ││ exclude [] default ││ variants ["2.0x","3.0x"] default ││ image_extensions ["png","jpg","jpeg","gif","webp", default ││ "bmp","wbmp"] │╰──────────────────────────────────────────────────────────────────────────────╯Without --verbose, it is max_kb: {"1.0x":500,"2.0x":1000,"3.0x":2000}.
A change of either key is listed among the configuration changes, with the value before and after. Writing a default limit again, such as {1.0x: 500}, changes nothing and is not listed.
Reading the files
Section titled “Reading the files”The asset inventory holds the size of every declared file, and is read once for every check of the run.
No fix
Section titled “No fix”There is no fix, and none is planned: an image is never resized or recompressed mechanically.