bluefireteam / photo_view

📸 Easy to use yet very customizable zoomable image widget for Flutter, Photo View provides a gesture sensitive zoomable widget. Photo View is largely used to show interacive images and other stuff such as SVG.
MIT License
1.91k stars 547 forks source link

Zoom with mouse wheel #481

Open cachapa opened 3 years ago

cachapa commented 3 years ago

On desktop the mouse wheel is ignored. The expected behavior would be for the image to zoom in when using the mouse wheel to scroll up and zoom out in the other direction.

tedfire commented 2 years ago

Hi I would like to support this. On Web we definitely need mouse support please !

topex-psy commented 2 years ago

Any updates on this? My flutter web app is in production and embarrassing that it can't even zoom image with mouse scroll.

Flutter's ScaleUpdateDetails should have scale property. It should be pretty easy. When scaleUpdates.pointerCount == 0 then it's a mouse scroll.

renancaraujo commented 2 years ago

A mouse scroll event doesn't fire any gesture recognizer because there is no pointer of contact. We should rather use pointer signal

mxkdev commented 6 months ago

Would be great to have this feature in the library, however here is my very basic workaround using onPointerSignal from Listener:

final _viewController = PhotoViewController();

Widget _buildPhotoView() {
    return Listener(
      onPointerSignal: (event) {
        if (event is PointerScrollEvent) {
          final delta = event.scrollDelta.dy;
          final controller = _viewController;
          if (controller != null) {
            final scale = controller.scale ?? 1.0;
            final newScale = scale - delta / 1000;
            controller.scale = newScale.clamp(1.0, 10.0);
          }
        }
      },
      child: PhotoView.customChild(
        child: FlutterLogo(),
        enablePanAlways: true,
        wantKeepAlive: true,
        backgroundDecoration: const BoxDecoration(color: Colors.grey),
        controller: _viewController,
      ),
    );
  }