Skip to content

InteractiveViewer with contrained = false, results in scale immediately jumping to maxScale and staying at that value. #88467

@safield

Description

@safield

Flutter 2.2.3 • channel stable • https://github.com/flutter/flutter.git
Framework • revision f4abaa0 (7 weeks ago) • 2021-07-01 12:46:11 -0700
Engine • revision 241c87ad80
Tools • Dart 2.13.4

I am using an InteractiveWidget for the use of is transform matrix. Ultimately I will be using the matrix to scale a path without scaling the stroke thickness by settings path.transform property.

In the following minimal example I have a CustomPainter that draws and updates based on the TransformController passed from a InteractiveViewer. I have set the constrained property to false.

As as I begin a a two finger zoom in gesture, the scale immediately jumps to maxScale value. In this case I get the following matrix...

[0] 8.0,0.0,0.0,-1474.117674624082
[1] 0.0,8.0,0.0,-2227.0196568174856
[2] 0.0,0.0,8.0,0.0
[3] 0.0,0.0,0.0,1.0

From that point forward, the scale always remains at maxScale, regardless if I try to zoom out. In other words, as soon as a scale in gesture occurs, the scale jumps to and permanently stays at maxScale.

Here is a minimal example:

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key? key}) : super(key: key);
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  TransformationController _transformController = TransformationController();
  @override
  void initState() { 
    super.initState();
    // _transformController.addListener(() { 
      // setState(() {
        // 
      // });
    // });
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Transform Test"),
      ),
      body: Center(
        child: Stack(
          children: [
            CustomPaint(
              painter: CustomLayer(
                context,
                _transformController,
              ),
              child: Container(),
            ),
            InteractiveViewer(
              transformationController: _transformController,
              constrained: false,
              maxScale: 8.0,
              minScale: 0.5,
              child: Container(),
            ),
          ],
        ),
      ),
    );
  }
}

class CustomLayer extends CustomPainter {
  TransformationController _transformationController;
  CustomLayer(
    BuildContext context,
    this._transformationController
  ) : super(repaint: _transformationController);

  @override
  void paint(Canvas canvas, Size size) {
    var circleRadius = 6.0;
    var x = size.width /  2 - circleRadius / 2;
    var y = size.height /  2 - circleRadius / 2;
    canvas.transform(_transformationController.value.storage);
    canvas.drawCircle(Offset(x,y), circleRadius, Paint()..color = Colors.red);
    print(_transformationController.value.toString());
  }

  @override
  bool shouldRepaint(CustomLayer oldDelegate) => true;
}

Metadata

Metadata

Assignees

Labels

f: material designflutter/packages/flutter/material repository.found in release: 2.2Found to occur in 2.2found in release: 2.5Found to occur in 2.5frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer version

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions