Repository: flutter
Issue: InteractiveViewer jumps to incorrect transform on mouse scroll during pan
Labels: framework,platform-web,a: desktop,a: mouse,has reproducible steps,P2,team-framework,triaged-framework,found in release: 3.24,found in release: 3.27

### Steps to reproduce

- Run the code sample on Windows or Web while using a mouse.
- Pan the InteractiveViewer grid with left or right mouse button.
- While the pan is in motion, place the mouse cursor on the blue square and use the mouse scroll wheel to scroll in or out.
- The zoom will NOT be focused on the current mouse location, rather the gesture will be centered on the point that the pan was initiated.

### Expected results

When the scroll wheel is used to zoom in or out, I would expect the InteractiveViewer to zoom in or out on the current location of the mouse cursor. In the sample code, anytime I try and zoom in or out while the cursor is on the blue square, I would expect the blue square to remain on screen and inside my mouse cursor.

### Actual results

If there is momentum from a pan gesture while scroll wheel is used to zoom in or out on my target (the blue square), the results will be unpredictable, and my desired zoom target (the blue square) will go offscreen.

### Code sample

<details open><summary>Code sample</summary>

```dart
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  late final TransformationController _controller = TransformationController(
    Matrix4(
      0.5, 0, 0, 0, //
      0, 0.5, 0, 0, //
      0, 0, 0.5, 0, //
      -2000, -2000, 0, 1, //
    ),
  );

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: InteractiveViewer(
        transformationController: _controller,
        constrained: false,
        minScale: 0.01,
        scaleFactor: 500,
        child: Stack(
          children: [
            const MapGrid(
              size: Size(
                10000,
                10000,
              ),
            ),
            Positioned(
              left: 4500,
              top: 4500,
              child: Container(
                color: Colors.blue,
                width: 1000,
                height: 1000,
              ),
            ),
          ],
        ),
      ),
    );
  }
}

class MapGrid extends StatelessWidget {
  const MapGrid({super.key, required this.size});

  final Size size;

  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context);

    return CustomPaint(
      painter: MapGridPainter(
        color: theme.colorScheme.primary,
      ),
      size: size,
    );
  }
}

class MapGridPainter extends CustomPainter {
  final Color color;

  final Paint _paint;

  MapGridPainter({super.repaint, required this.color})
      : _paint = Paint()
          ..color = color
          ..strokeWidth = 1;

  @override
  void paint(Canvas canvas, Size size) {
    for (double x = 0; x < size.width; x += 100) {
      canvas.drawLine(Offset(x, 0), Offset(x, size.height), _paint);
    }

    for (double y = 0; y < size.height; y += 100) {
      canvas.drawLine(Offset(0, y), Offset(size.width, y), _paint);
    }
  }

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) {
    return true;
  }
}

```

</details>


### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>

[Upload media here]

</details>


### Logs

<details open><summary>Logs</summary>

```console
[Paste your logs here]
```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
[√] Flutter (Channel stable, 3.24.3, on Microsoft Windows [Version 10.0.22631.4460], locale en-US)
    • Flutter version 3.24.3 on channel stable at D:\GitHub\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 2663184aa7 (3 months ago), 2024-09-11 16:27:48 -0500
    • Engine revision 36335019a8
    • Dart version 3.5.3
    • DevTools version 2.37.3

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at C:\Users\sheri\AppData\Local\Android\sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 21.0.3+-12282718-b509.11)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Professional 2022 17.9.2)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Professional
    • Visual Studio Professional 2022 version 17.9.34622.214
    • Windows 10 SDK version 10.0.22621.0

[√] Android Studio (version 2024.2)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 21.0.3+-12282718-b509.11)

[√] VS Code (version 1.95.3)
    • VS Code at C:\Users\sheri\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.102.0

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.22631.4460]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 131.0.6778.69
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 131.0.2903.70

[√] Network resources
    • All expected network resources are available.

• No issues found!
```

</details>