Skip to content

[vector_graphics] Respect BoxFit parameter with viewbox#11012

Merged
auto-submit[bot] merged 8 commits intoflutter:mainfrom
SWI-Swissinfo-ch:158496-vector-boxfit
Mar 10, 2026
Merged

[vector_graphics] Respect BoxFit parameter with viewbox#11012
auto-submit[bot] merged 8 commits intoflutter:mainfrom
SWI-Swissinfo-ch:158496-vector-boxfit

Conversation

@Gustl22
Copy link
Contributor

@Gustl22 Gustl22 commented Feb 12, 2026

Closes flutter/flutter#158496

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

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 3

@Gustl22 Gustl22 requested a review from jtmcdole as a code owner February 12, 2026 22:17
@github-actions github-actions bot added p: vector_graphics triage-engine Should be looked at in engine triage labels Feb 12, 2026
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

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 fixes an issue where BoxFit was not being respected for vector graphics with a viewBox. The change refactors the sizing logic in _VectorGraphicWidgetState to correctly use FittedBox. The PR also renames an internal variable for clarity and adds extensive new tests, including golden file tests, to verify the fix. The changes are logical and well-tested. I've included a few minor suggestions to align with Dart's style guide.

@Gustl22 Gustl22 force-pushed the 158496-vector-boxfit branch from 81bbbe6 to baa096a Compare February 12, 2026 22:23
@Gustl22
Copy link
Contributor Author

Gustl22 commented Feb 16, 2026

It seems, that the goldens fail, although they succeed locally on my Mac. As I am not sure, if we should keep them anyways, I wait until generating on Linux (as I need to set it up then).

});
});

// TODO(gustl22): can be removed if redundant
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can remove goldens (if too costly for CI), but maybe is a good thing to have them in place (more intuitive to see, what's going on).

@Gustl22
Copy link
Contributor Author

Gustl22 commented Mar 4, 2026

@jtmcdole you are assigned as reviewer. Is it feasable to triage or delegate reviewing this PR? Thanks for your time.

@jtmcdole
Copy link
Member

jtmcdole commented Mar 6, 2026

@jtmcdole you are assigned as reviewer. Is it feasable to triage or delegate reviewing this PR? Thanks for your time.

I must have been auto-assigend for owners reasons. When I see failing tests, I usually assume the PR is still in flux. Any chance you can address the failures first?

@Gustl22
Copy link
Contributor Author

Gustl22 commented Mar 6, 2026

@jtmcdole thank you for getting back. As I wrote here, it would be good to know, if goldens are actually desired in this case:
#11012 (comment)
I additionally wrote tests which work without goldens and they pass.
The goldens I wrote also pass locally on mac, but fail on CI probably due to different plaform rendering on Linux.

@gaaclarke
Copy link
Member

If you are having a hard time creating a golden that passes on macos and linux, can't you just add 2 different goldens, one for each platform?

@Gustl22
Copy link
Contributor Author

Gustl22 commented Mar 10, 2026

@gaaclarke thank you for your proposal, I will probably remove my golden tests, as they still fail on CI even if rendered on Linux locally.
I would have liked the goldens as one can better see the transfomations. But they also don't exist for testing regular Boxfit images (maybe for that reason of conflicting rendering output).
I still test the boundaries already, though:
https://github.com/flutter/packages/pull/11012/changes#diff-6439a450e367819d9c9b7e7dd52cf4e8932ae767afd5850ef477b58d4bc65dd5R208

I would have liked to get a comment on what is your preferred testing strategy:

  • testing via goldens only
    • more intuitive to see the outcome
    • probably costly to check
    • increases repository size
    • problems on rendering on different platforms
  • test by checking transformed boundaries only
    • fast to check
    • precise values one can proof via calculation
    • cannot see the effect at first glance (via an image)
  • keep both tests separately
  • keep both but combine them each in one test case for boundary & golden testing together

@Gustl22
Copy link
Contributor Author

Gustl22 commented Mar 10, 2026

I removed the redundant golden tests for now. If not sufficient, we can think about the approach how to add them. All tests pass now.

Copy link
Member

@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

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

Code looks good and I ran the it locally with the reproduction code to verify it does fix the problem. Thanks!

@Gustl22 Gustl22 changed the title [vector_graphics] Respect BoxFit parameter with viewbox (closes #158496) [vector_graphics] Respect BoxFit parameter with viewbox Mar 10, 2026
Copy link
Member

@jtmcdole jtmcdole left a comment

Choose a reason for hiding this comment

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

LFTM

@gaaclarke gaaclarke added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 10, 2026
@auto-submit auto-submit bot merged commit a643267 into flutter:main Mar 10, 2026
81 checks passed
@Gustl22 Gustl22 deleted the 158496-vector-boxfit branch March 11, 2026 10:34
github-merge-queue bot pushed a commit to flutter/flutter that referenced this pull request Mar 11, 2026
flutter/packages@ee460d6...ecace66

2026-03-11 srawlins@google.com [pigeon] Produce a helpful error for bad
method return type (flutter/packages#11204)
2026-03-11 srawlins@google.com [pigeon] Use hasLength and isEmpty in
tests for better failure messages (flutter/packages#11205)
2026-03-11 dacoharkes@google.com [rfw] Opt out of icon tree shaking
(flutter/packages#11216)
2026-03-11 srawlins@google.com [pigeon] Tidy imports and "ignore"
comments (flutter/packages#11149)
2026-03-11 49699333+dependabot[bot]@users.noreply.github.com
[dependabot]: Bump org.jetbrains.kotlin:kotlin-bom from 2.2.21 to 2.3.10
in /packages/pigeon/platform_tests/test_plugin/android
(flutter/packages#10984)
2026-03-11 srawlins@google.com [pigeon] Improve casting and
nullability-handling in generated code (flutter/packages#11163)
2026-03-10 engine-flutter-autoroll@skia.org Roll Flutter from
2ec61af to 195ae7b (36 revisions) (flutter/packages#11222)
2026-03-10 git@reb0.org [vector_graphics] Respect BoxFit parameter with
viewbox (flutter/packages#11012)
2026-03-10 stuartmorgan@google.com Add AI contribution guidelines to PR
checklist (flutter/packages#11195)
2026-03-10 zezohassam@gmail.com [video_player] Optimize caption
retrieval with binary search in VideoPlayerController
(flutter/packages#8347)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC flutter-ecosystem@google.com 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 p: vector_graphics triage-engine Should be looked at in engine triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[flutter_svg] Incorrect behavior of BoxFit parameter

3 participants