Thanks to visit codestin.com
Credit goes to github.com

Skip to content

InteractiveViewer should allow us to easily customize the inertia physics #71676

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
esDotDev opened this issue Dec 3, 2020 · 8 comments
Open
Labels
a: desktop Running on desktop c: new feature Nothing broken; request for a new capability c: proposal A detailed proposal for a change to Flutter f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. P3 Issues that are less important to the Flutter project team-framework Owned by Framework team triaged-framework Triaged by Framework team

Comments

@esDotDev
Copy link

esDotDev commented Dec 3, 2020

On desktop and web, it is usually not desired to have inertia, when using these types of viewers with mouse.

Behavior is variable. For example Adobe XD, or Figma, when you drag an artboard and release, it's a hard stop. On photoshop though, it uses inertia.

It would be nice if we could supply our own drag coefficient (kDrag), or our own FrictionSimulation entirely.

To think a bit beyond that though, Unity has a very similar component, but it has configuration options that are more flexible.
image

Some config options that would be nice for a widget of this type, from a production perspective:

  • Vt/Hz/Both scroll modes
  • Clamped / Elastic Type (If clamped, overscroll is not allowed, otherwise it's ios bounce-back style)
  • Inertia toggle (If disable, there's no inertia at all, hard stop)
    • Deceleration Rate (friction)
  • Pan & Scale Sensitivity
    • It would be nice if this was divided between mouseWheel and touch, since these are often independent vars and need fine tuning.
@darshankawar darshankawar added a: desktop Running on desktop f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. passed first triage platform-web Web applications specifically c: proposal A detailed proposal for a change to Flutter labels Dec 4, 2020
@yjbanov yjbanov added c: new feature Nothing broken; request for a new capability and removed platform-web Web applications specifically labels Dec 10, 2020
@yjbanov
Copy link
Contributor

yjbanov commented Dec 10, 2020

Removed the web label as this applies to all platforms.

@gspencergoog gspencergoog added the P3 Issues that are less important to the Flutter project label Jan 7, 2021
@justinmc
Copy link
Contributor

Maybe InteractiveViewer should have something like ScrollPhysics?

@BaileyHelfer
Copy link

I was able to get something similar by changing the interactionEndFrictionCoefficient parameter to a very small number so the drag on an image is very minimal. When I made the parameter = 1.0 it was perfect but I was getting the following error so I decided to make it as small as possible:

══╡ EXCEPTION CAUGHT BY ANIMATION LIBRARY ╞═════════════════════════════════════════════════════════
The following LateError was thrown while notifying listeners for AnimationController:
LateInitializationError: Local 'closestOverall' has not been initialized.

When the exception was thrown, this was the stack:
#0      LateError._throwLocalNotInitialized (dart:_internal-patch/internal_patch.dart:197:5)
#1      InteractiveViewer.getNearestPointInside (package:flutter/src/widgets/interactive_viewer.dart:536:12)
#2      _exceedsBy (package:flutter/src/widgets/interactive_viewer.dart:1428:51)
#3      _InteractiveViewerState._matrixTranslate (package:flutter/src/widgets/interactive_viewer.dart:650:38)
#4      _InteractiveViewerState._onAnimate (package:flutter/src/widgets/interactive_viewer.dart:1099:40)
#5      AnimationLocalListenersMixin.notifyListeners (package:flutter/src/animation/listener_helpers.dart:161:19)
#6      AnimationController._tick (package:flutter/src/animation/animation_controller.dart:830:5)
#7      Ticker._tick (package:flutter/src/scheduler/ticker.dart:249:12)
#8      SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1284:15)
#9      SchedulerBinding.handleBeginFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:1136:11)
#10     _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:625:13)
#11     SchedulerBinding.handleBeginFrame (package:flutter/src/scheduler/binding.dart:1134:17)
#12     SchedulerBinding._handleBeginFrame (package:flutter/src/scheduler/binding.dart:1051:5)
#13     _invoke1 (dart:ui/hooks.dart:158:13)
#14     PlatformDispatcher._beginFrame (dart:ui/platform_dispatcher.dart:337:5)
#15     _beginFrame (dart:ui/hooks.dart:101:31)

The AnimationController notifying listeners was:
  AnimationController#08675(▶ 0.018)
════════════════════════════════════════════════════════════════════════════════════════════════════

@Balin-P
Copy link

Balin-P commented Oct 3, 2023

For my use case, the friction/inertia was messing with an animation I wanted to trigger once the user stops scaling the viewer. I ended up just making a copy of the source code for InteractiveViewer and commenting out line 969, which disables it:

_scaleAnimation!.addListener(_onScaleAnimate);

There really should be an option for this though. Something similar to ScrollPhysics would be cool, but at least setting the interactionEndFrictionCoefficient parameter to 0 should disable it, rather than just being invalid.

@ductranit
Copy link

Hi there,
I got the same error with InteractiveViewer from crashlytics like this:

      Fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: LateInitializationError: Local 'closestOverall' has not been initialized.. Error thrown while handling a gesture.
       at LateError._throwLocalNotInitialized(dart:_internal)
       at InteractiveViewer.getNearestPointInside(interactive_viewer.dart:536)
       at ._exceedsBy(interactive_viewer.dart:1428)
       at _InteractiveViewerState._matrixTranslate(interactive_viewer.dart:650)
       at _InteractiveViewerState._onScaleUpdate(interactive_viewer.dart:889)
       at ScaleGestureRecognizer._advanceStateMachine.<fn>(scale.dart:702)
       at GestureRecognizer.invokeCallback(recognizer.dart:275)
       at ScaleGestureRecognizer._advanceStateMachine(scale.dart:701)
       at ScaleGestureRecognizer.handleEvent(scale.dart:553)
       at PointerRouter._dispatch(pointer_router.dart:98)
       at PointerRouter._dispatchEventToRoutes.<fn>(pointer_router.dart:143)
       at _LinkedHashMapMixin.forEach(dart:collection)
       at PointerRouter._dispatchEventToRoutes(pointer_router.dart:141)
       at PointerRouter.route(pointer_router.dart:127)
       at GestureBinding.handleEvent(binding.dart:488)
       at GestureBinding.dispatchEvent(binding.dart:468)
       at RendererBinding.dispatchEvent(binding.dart:333)
       at GestureBinding._handlePointerEventImmediately(binding.dart:413)
       at GestureBinding.handlePointerEvent(binding.dart:376)
       at GestureBinding._flushPointerEventQueue(binding.dart:323)
       at GestureBinding._handlePointerDataPacket(binding.dart:292)

But I can't reproduce it on my devices.
Here is my code:

 InteractiveViewer(
                transformationController: transformationController,
                minScale: 1,
                maxScale: 10,
                child: GestureDetector(
                    onTapUp: readerController.tap,
                    child: SizedBox(
                        width: spreadSize.width,
                        height: spreadSize.height,
                        child: Stack(
                            children: _buildCanvas(spreadSize, context)))))

I don't set the interactionEndFrictionCoefficient value, so it's just default 0.0000135

Do you know how can I fix this crash?

@cbracken cbracken added team-framework Owned by Framework team and removed team-desktop labels Jun 7, 2024
@flutter-triage-bot
Copy link

The triaged-desktop label is irrelevant if there is no team-desktop label or fyi-desktop label.

@goderbauer goderbauer added the triaged-framework Triaged by Framework team label Jun 10, 2024
@sysint64
Copy link
Contributor

sysint64 commented Oct 18, 2024

Setting interactionEndFrictionCoefficient to double.infinity disabled inertia completely for me, it works on iOS.

@enhancient
Copy link

enhancient commented May 6, 2025

Maybe InteractiveViewer should have something like ScrollPhysics?

I've had a go implementing ScrollPhysics in InteractiveViewer by constructing 'synthetic' ScrollMetrics for the InteractiveViewer and applying the physics from the specified ScrollPhysics to offsets outside of the bounds. I've also tried to leverage the ScrollPhysics in the case of zooming beyond maxScale and below minScale. Obviously ScrollPhysics doesn't currently consider zooming, so I took the approach of calculating the extent the content bounds would be exceeded when zooming beyond the maxScale and applying the ScrollPhysics to that offset to provide friction (in the case of BouncingScrollPhysics). Is this the kind of thing you had in mind?

InteractiveViewerScrollPhysics

video

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: desktop Running on desktop c: new feature Nothing broken; request for a new capability c: proposal A detailed proposal for a change to Flutter f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. P3 Issues that are less important to the Flutter project team-framework Owned by Framework team triaged-framework Triaged by Framework team
Projects
None yet
Development

No branches or pull requests