Skip to content

[cupertino_ui] Fix CupertinoMagnifier focal point with custom size - #13029

Merged
auto-submit[bot] merged 2 commits into
flutter:mainfrom
HibaChamkhi:fix-cupertino-magnifier-custom-size-151740
Oct 2, 2026
Merged

auto-submit[bot] merged 2 commits into
flutter:mainfrom
HibaChamkhi:fix-cupertino-magnifier-custom-size-151740

Conversation

@HibaChamkhi

Copy link
Copy Markdown
Contributor

CupertinoMagnifier used kDefaultSize.height instead of size.height to compute its focal point, so magnified content was not vertically centered with a custom size. The default size is unchanged.

Fixes flutter/flutter#151740

Pre-Review Checklist

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2

CupertinoMagnifier computed its focal point offset from kDefaultSize
instead of the size it was given, so magnifiers with a custom size did
not center the magnified content vertically.

Fixes flutter/flutter#151740
@github-actions github-actions Bot added p: cupertino_ui triage-design Should be looked at in design triage labels Sep 26, 2026

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request updates CupertinoMagnifier to calculate its focal point offset using its actual size instead of kDefaultSize, and adds a corresponding widget test. Feedback points out that Offset is immutable, meaning the call to focalPointOffset.scale(...) does not mutate the variable and the animation scale is currently ignored. A correction is suggested to apply the scale directly during initialization.

@override
Widget build(BuildContext context) {
var focalPointOffset = Offset(0, (kDefaultSize.height / 2) - kMagnifierAboveFocalPoint);
var focalPointOffset = Offset(0, (size.height / 2) - kMagnifierAboveFocalPoint);

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.

high

The Offset class in Flutter is immutable. Calling focalPointOffset.scale(...) on line 357 returns a new Offset but does not mutate the existing one, meaning the animation scale is currently ignored. To fix this, you can apply the scale directly during the initialization of focalPointOffset on this line, and then remove the redundant focalPointOffset.scale(...) call on line 357.

    var focalPointOffset = Offset(0, ((size.height / 2) - kMagnifierAboveFocalPoint) * (inOutAnimation?.value ?? 1));

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.

Hmm, that's true.

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.

Could you take a look at this comment from Gemini? It seems to be an existing issue, so I'm not sure if we should fix it here or create a separate issue for it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing it out! You're right, scale is a no-op because Offset is immutable, but it was already like that before this PR. Fixing it would change the in/out animation of every CupertinoMagnifier, not only custom sizes, so I think it's better handled in a separate issue. I'm happy to open one and work on it.

@Mairramer Mairramer added the CICD Run CI/CD label Sep 28, 2026
@Mairramer
Mairramer self-requested a review September 28, 2026 19:46

@Mairramer Mairramer 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.

Thanks for the PR. Everything LGTM. Just one comment.

Comment thread packages/cupertino_ui/test/magnifier_test.dart Outdated
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Sep 29, 2026
@Mairramer Mairramer added the CICD Run CI/CD label Sep 29, 2026
@elliette
elliette requested a review from Piinks September 29, 2026 21:16

@Piinks Piinks 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.

LGTM! Thank you!

@Piinks Piinks added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 2, 2026
@auto-submit
auto-submit Bot merged commit 8dcefb4 into flutter:main Oct 2, 2026
14 checks passed
ZhuJHua pushed a commit to ZhuJHua/flutter that referenced this pull request Oct 6, 2026
…er#193840)

flutter/packages@5620e65...951f2f7

2026-10-05 [email protected] [material_ui] Add scrollPadding
property to DropdownMenuFormField (flutter/packages#12735)
2026-10-02 [email protected] [material_ui]
Migrate M3 Motion template to use new gen_defaults
(flutter/packages#13058)
2026-10-02 [email protected]
[cupertino_ui] Forward showDragHandle from showCupertinoSheet to
CupertinoSheetRoute (flutter/packages#13011)
2026-10-02 [email protected] [cupertino_ui]
Fix CupertinoMagnifier focal point with custom size
(flutter/packages#13029)
2026-10-02 [email protected] [ci] Add material_ui and cupertino_ui
to customer testing (flutter/packages#13114)
2026-10-02 [email protected] [material_ui]
Add Material 3 Expressive migration skill (flutter/packages#12818)
2026-10-02 [email protected] [video_player] Ignore late position
updates after disposal (flutter/packages#12971)
2026-10-02 [email protected] [material_ui]
Remove unconditional dart:io import from about.dart
(flutter/packages#12774)
2026-10-02 [email protected] [material_ui] Fix
DropdownButtonFormField underline alignment at bottom
(flutter/packages#12606)
2026-10-02 [email protected] Roll Flutter from
e89fd0a to d03768e (23 revisions) (flutter/packages#13111)
2026-10-02 [email protected] [material_ui] Migrate
`Switch` API doc snippets to {@example} (batch 8)
(flutter/packages#13052)
2026-10-02 [email protected]
[url_launcher] Fix supportsCloseForLaunchMode to query close support
(flutter/packages#12926)
2026-10-02 [email protected] Redistribute
iOS/macOS Suggested Reviewers (flutter/packages#13076)
2026-10-02 [email protected] [image_picker] Subsample large images
when resizing on Android (flutter/packages#13038)
2026-10-02 [email protected] [cupertino_ui] Remove
redundant null arguments in Completer.complete (flutter/packages#13008)
2026-10-02 [email protected] [repo]
Update AGENTS.md with dependency allowance and versioning guidance
(flutter/packages#12579)

If this roll has caused a breakage, revert this CL and set the roller
to dry run mode using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected] on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD p: cupertino_ui triage-design Should be looked at in design triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CupertinoMagnifier is not centered vertically with custom size

3 participants