Skip to content

fix(pick): carry the size of an image pick - #246

Merged
anilcancakir merged 2 commits into
masterfrom
fix/pick-image-size
Oct 19, 2026
Merged

anilcancakir merged 2 commits into
masterfrom
fix/pick-image-size

Conversation

@anilcancakir

Copy link
Copy Markdown
Member

What

Pick.image, Pick.images, Pick.camera, Pick.media, Pick.video and Pick.recordVideo now set MagicFile.size, from XFile.length().

Why

The image_picker conversion built every MagicFile without a size, on every platform. A caller guarding an upload limit read size == null and let every oversize image through. Found in Uptizm's status page logo upload: on the web a 3 MB PNG skipped the client's 512 KB check, reached PHP's 2 MB ceiling and came back as an unexplained "The logo failed to upload". file_picker picks already carry a size (PlatformFile.length()); this brings image picks in line. On the web XFile.length() is the blob's size, so nothing is read into memory.

Changes

  • lib/src/facades/pick.dart: _xFileToMagicFile is async and sets size: await xFile.length(); every call site awaits it (Pick.images through Future.wait).
  • test/facades/pick_test.dart: Pick.image and Pick.images carry the size, through a fake ImagePickerPlatform.
  • pubspec.yaml: image_picker_platform_interface as a dev dependency for that fake.

Testing

  • flutter test: 2360 passed.
  • flutter analyze: no issues.
  • dart format --set-exit-if-changed .: clean.

@codecov

codecov Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@kodizm

kodizm Bot commented Oct 19, 2026

Copy link
Copy Markdown

Note

Kodizm (AI-generated). May contain mistakes; verify before acting.

Correct fix, properly awaited at every call site; one coverage gap worth closing before merge.

Minor

lib/src/facades/pick.dart:163,205,227,268: camera(), media(), video() and recordVideo() all route through the same now-async _xFileToMagicFile, but the new tests only exercise Pick.image()/Pick.images(). codecov/patch flags this directly (50% of the diff hit vs. the 83.17% target) — worth a quick size assertion for at least one more of these paths, per the repo's TDD rule in CLAUDE.md ("no production code without a failing test that fails for the right reason").

All six call sites correctly add await/Future.wait, and the two wrapped in try/catch (camera, recordVideo) still cover a thrown XFile.length() the same way they covered the old synchronous path, so no regression there.

Tests

New tests cover Pick.image and Pick.images size propagation via a fake ImagePickerPlatform; camera, media, video, and recordVideo share the changed helper but aren't directly asserted on size, matching the codecov miss above.

CI

  • Lint & Test: success
  • Generated code analyzes: success
  • Internal Links & Anchors: success
  • codecov/patch: failure (50.00% of diff hit, target 83.17%)
  • Auto-merge low-risk Dependabot PRs, External Links: skipped (not applicable to this PR)

@anilcancakir

Copy link
Copy Markdown
Member Author

Minor (lib/src/facades/pick.dart:163,205,227,268, codecov/patch): fixed in bb272ac. test/facades/pick_test.dart adds "a camera, media, video and recorded video pick carry the size", which asserts size through Pick.camera, Pick.media, Pick.video and Pick.recordVideo against the fake ImagePickerPlatform (now answering getMedia and getVideo too). flutter test test/facades/pick_test.dart: 22 passed; flutter analyze and dart format --set-exit-if-changed . clean.

@kodizm please re-review.

@kodizm

kodizm Bot commented Oct 19, 2026

Copy link
Copy Markdown

Note

Kodizm (AI-generated). May contain mistakes; verify before acting.

Coverage gap closed; approving.

The only prior finding (missing size assertions for camera, media, video, recordVideo) is fixed in bb272ac: test/facades/pick_test.dart's "a camera, media, video and recorded video pick carry the size" test now exercises all four through the extended _FakeImagePicker (answering getMedia/getVideo in addition to getImageFromSource/getMultiImageWithOptions). No new issues in this update.

Tests

All six Pick.* entry points that route through _xFileToMagicFile now have a size assertion.

CI

  • Lint & Test: success
  • Generated code analyzes: success
  • Internal Links & Anchors: success
  • codecov/patch: success (100.00% of diff hit, target 83.17%)
  • Auto-merge low-risk Dependabot PRs, External Links: skipped (not applicable to this PR)

@anilcancakir
anilcancakir merged commit 698c1e7 into master Oct 19, 2026
7 checks passed
@anilcancakir anilcancakir mentioned this pull request Oct 19, 2026
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