Skip to content

Allow a zero scale change in InteractiveViewer - #194949

Merged
auto-submit[bot] merged 4 commits into
flutter:masterfrom
YeungKC:fix-82115-interactive-viewer-zero-scale
Nov 6, 2026
Merged

auto-submit[bot] merged 4 commits into
flutter:masterfrom
YeungKC:fix-82115-interactive-viewer-zero-scale

Conversation

@YeungKC

@YeungKC YeungKC commented Oct 21, 2026

Copy link
Copy Markdown
Member

InteractiveViewer asserts scale != 0.0 in _matrixScale. Some inputs give a scale change of 0.0, and then the assert fails. These inputs reach a scale change of 0.0:

  • A pinch that moves both pointers to the same point. ScaleUpdateDetails.scale is then 0.0. A pointer distance of 1e-300 also gives 0.0, because the coordinates round to the same value.
  • A trackpad pan-zoom gesture with a scale of 0.0.
  • A PointerScaleEvent with a scale of 0.0.
  • A mouse wheel scroll with a very large scrollDelta.dy, or with a very small scaleFactor. Then math.exp(-event.scrollDelta.dy / widget.scaleFactor) underflows to 0.0.
  • A trackpad scroll with trackpadScrollCausesScale: true and a very large delta.

All of these inputs go through _matrixScale.

The code after the assert already handles a scale change of 0.0. It clamps the total scale with clampDouble(totalScale, widget.minScale, widget.maxScale), and the constructor asserts minScale > 0. Thus, the new scale is at least minScale, and the matrix values stay finite. The assert does not stop a negative scale change. Before this change, PointerScaleEvent(scale: -1) already went through the same clamp with no error. A scale change of 0.0 follows the same path.

This PR removes the assert. For a scale change that is not 0.0, the behavior does not change.

Fixes #82115

Tests

I added two regression tests to packages/flutter/test/widgets/interactive_viewer_test.dart. They use two different input paths to _matrixScale:

  • The first test moves two pointers to the same point. This input goes through the scale gesture handlers.
  • The second test sends a PointerScaleEvent with a scale of 0.0. This input goes through the pointer signal handler.

Each test makes sure that no exception occurs, that all matrix values are finite, and that the scale is more than 0.0.

New tests test/widgets
Before Both fail: 'scale != 0.0': is not true (interactive_viewer.dart line 647) 1 failure
After Both pass (interactive_viewer_test.dart: +62, all tests passed) 1 failure, the same test as before

The 1 failure also occurs on the base commit without this change. It is ext.flutter.inspector.screenshot in widget_inspector_test.dart, and it depends on the local environment.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the AI contribution guidelines and understand my responsibilities, or I am not using AI tools.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant in-code documentation (doc comments with ///). No doc change is necessary.
  • If this PR introduces a new feature or capability, I created and linked a website documentation issue or PR in flutter/website (or verified none is needed). This PR does not add a feature.
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • I followed the breaking change policy and added Data Driven Fixes where supported.
  • All existing and new tests are passing. The test/widgets tests pass locally, except one test that also fails on the base commit. The other tests run only in CI.

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

_matrixScale asserted that the scale change is not 0.0. A pinch that
moves both pointers to one point, a trackpad pan-zoom, or a
PointerScaleEvent can give a scale change of 0.0. The clamp to minScale
and maxScale that follows already gives a valid matrix for this value.

Fixes flutter#82115
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Oct 21, 2026
@github-actions github-actions Bot added the framework flutter/packages/flutter repository. See also f: labels. label Oct 21, 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 removes the assert(scale != 0.0); statement from _InteractiveViewerState in interactive_viewer.dart. Additionally, it introduces two regression tests in interactive_viewer_test.dart to ensure that pinching both pointers to the same point and receiving a scale pointer event with a scale of 0.0 do not trigger exceptions. No review comments were provided for this pull request.

navaronbracke
navaronbracke previously approved these changes Oct 21, 2026

@navaronbracke navaronbracke 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 with nit

navaronbracke
navaronbracke previously approved these changes Oct 21, 2026

@victorsanni victorsanni 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 pending review from Justin who wrote InteractiveViewer.

Use an infinite boundaryMargin and minScale 0.1, so the clamp to minScale is the active guard. Expect the exact end scale of 0.1.
@victorsanni

Copy link
Copy Markdown
Contributor

Hi, is this ready for re-review? Please remember to request a review if it is, so it gets back into the review queue.

@YeungKC
YeungKC requested a review from victorsanni October 30, 2026 13:34

@victorsanni victorsanni 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

@victorsanni victorsanni added autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD and removed CICD Run CI/CD labels Nov 5, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Nov 6, 2026
Merged via the queue into flutter:master with commit b5b65f2 Nov 6, 2026
40 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 6, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Nov 6, 2026
Roll Flutter from 3623d2d34543 to 09175cdeac89 (61 revisions)

flutter/flutter@3623d2d...09175cd

2026-11-06 [email protected] Roll Skia from ae35b7b2221f to 793b8ac73d4b (3 revisions) (flutter/flutter#196091)
2026-11-06 [email protected] [web] Rasterize scenes at the size passed to `FlutterView.render` (flutter/flutter#196052)
2026-11-06 [email protected] Roll Skia from 4aa043a81e0c to ae35b7b2221f (1 revision) (flutter/flutter#196086)
2026-11-06 [email protected] Roll Fuchsia Linux SDK from Fqe3UlLwAohsPbsCS... to KIc0XZbhLmvDpTluZ... (flutter/flutter#196085)
2026-11-06 [email protected] Allow a zero scale change in InteractiveViewer (flutter/flutter#194949)
2026-11-06 [email protected] Roll Skia from dd5c2553a856 to 4aa043a81e0c (2 revisions) (flutter/flutter#196079)
2026-11-06 [email protected] [web] Keep ImageFilter.blur bounds in equality and description (flutter/flutter#196013)
2026-11-06 [email protected] iOS: Remove unused PlatformViewIOS setup from FlutterPlatformViewsTest (flutter/flutter#196033)
2026-11-06 [email protected] Serialize LoggerTests that mutate the shared Logger (flutter/flutter#196028)
2026-11-06 [email protected] Use reverseDuration for the AnimatedCrossFade size animation (flutter/flutter#194860)
2026-11-05 [email protected] Roll Skia from a5aacd103e68 to dd5c2553a856 (8 revisions) (flutter/flutter#196073)
2026-11-05 [email protected] Fix ListWheelScrollView null check error when it reads itemIndex before content dimensions are set (flutter/flutter#194859)
2026-11-05 [email protected] Allow zero cross axis extent in SliverGridDelegateWithMaxCrossAxisExtent (flutter/flutter#194858)
2026-11-05 [email protected] Revert: Allow color delta tolerance in in-memory fuzzy image comparator (flutter/flutter#196067)
2026-11-05 [email protected] Revert: Mitigate snapshot race in 3D transform test by reducing loop density (flutter/flutter#196066)
2026-11-05 [email protected] Delegate createStream in ResizeImage and ScrollAwareImageProvider (flutter/flutter#194756)
2026-11-05 [email protected] [iOS] Introduce FlutterShell and move thread host and profiler (flutter/flutter#195388)
2026-11-05 [email protected] [web] Support FragmentShader.getImageSampler on CanvasKit and Skwasm (flutter/flutter#195854)
2026-11-05 [email protected] Deprecates setFloat API (flutter/flutter#195505)
2026-11-05 [email protected] [flutter_tools] Remove public GlobalToolContext and globals from runner (flutter/flutter#195561)
2026-11-05 [email protected] Defer TLHC PlatformViewWrapper frame post and avoid initial 1x1 buffer resize (flutter/flutter#195861)
2026-11-05 [email protected] Roll Skia from b5abed66da86 to a5aacd103e68 (17 revisions) (flutter/flutter#196054)
2026-11-05 [email protected] Made `FlutterWindowControllerSizeTest.SizedToContentNotResizable` more robust (flutter/flutter#195845)
2026-11-05 [email protected] Update docs for contributor ladder (flutter/flutter#196011)
2026-11-05 [email protected] [Impeller] Use the transfer stage for the Vulkan readback barrier (flutter/flutter#194991)
2026-11-05 [email protected] Remove Mac mac_unopt builder (flutter/flutter#196027)
2026-11-05 [email protected] Updated Instructions for Determining Gradle Version for `gradle_dists` in CIPD (flutter/flutter#193310)
2026-11-05 [email protected] Move ios_app_with_extensions_test into the tool integration shard (flutter/flutter#195609)
2026-11-05 [email protected] [web] Respect Uint8List view bounds when detecting animated WebP/GIF (flutter/flutter#196010)
2026-11-05 [email protected] Add platform_views_layout to build_tests so iOS/Android build breaks are caught in presubmit (flutter/flutter#192985)
2026-11-05 [email protected] [flutter_tools] Detect macOS TCC permission crashes and provide diagnostic guidance (flutter/flutter#192432)
2026-11-05 [email protected] Roll Packages from 670b30e to 0478162 (15 revisions) (flutter/flutter#196047)
2026-11-05 [email protected] [web] Support Skwasm rendering without bitmap capture (flutter/flutter#195103)
2026-11-05 [email protected] [flutter_tools] Reland fix for local CanvasKit asset paths on Windows (flutter/flutter#195770)
2026-11-05 [email protected] Roll Skia from f96be51af95d to b5abed66da86 (14 revisions) (flutter/flutter#196017)
2026-11-05 [email protected] Split chrome web engine test drone (flutter/flutter#195873)
2026-11-05 [email protected] Roll Dart SDK from c9153304136a to 6623b84628f3 (1 revision) (flutter/flutter#196026)
2026-11-05 [email protected] Roll ICU from 4fe960221710 to a0ea93436c52 (6 revisions) (flutter/flutter#196025)
2026-11-05 [email protected] Add more guidance in README and AGENTS for contributing to flutter_tools (flutter/flutter#195998)
2026-11-05 [email protected] Roll Fuchsia Linux SDK from p0HDXLISPIElJfSz7... to Fqe3UlLwAohsPbsCS... (flutter/flutter#196019)
2026-11-05 [email protected] Roll Dart SDK from e362a23e9738 to c9153304136a (18 revisions) (flutter/flutter#196014)
2026-11-05 [email protected] [Impeller] Fix dilation input bounds when clipping saveLayers (flutter/flutter#195652)
2026-11-05 [email protected] Add `variantOf` to the M3E migration checklist (flutter/flutter#195099)
2026-11-05 [email protected] [flutter_tools] Eliminate globals from remaining subsystem files (flutter/flutter#195555)
2026-11-05 [email protected] Fix gap flipping when dragging variable height reorderable items (flutter/flutter#194478)
2026-11-05 [email protected] [A11y] Send un-merged SemanticsNodes in the same update that first references them (flutter/flutter#195829)
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

InteractiveViewer 'scale != 0.0': is not true

3 participants