Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void _handleScaleStart(ScaleStartDetails details) {
- setState(() {
- _startingFocalPoint = details.focalPoint;
- _previousOffset = _offset;
- _previousZoom = _zoom;
- });
- }
- void _handleScaleUpdate(ScaleUpdateDetails details) {
- setState(() {
- _zoom = _previousZoom * details.scale;
- // Ensure that item under the focal point stays in the same place despite zooming
- final Offset normalizedOffset = (_startingFocalPoint - _previousOffset) / _previousZoom;
- _offset = details.focalPoint - normalizedOffset * _zoom;
- });
- }
- @override
- Widget build(BuildContext context) {
- return Stack(
- fit: StackFit.expand,
- children: <Widget>[
- GestureDetector(
- onScaleStart: _scaleEnabled ? _handleScaleStart : null,
- onScaleUpdate: _scaleEnabled ? _handleScaleUpdate : null,
- child: CustomPaint(
- painter: _GesturePainter(
- zoom: _zoom,
- offset: _offset,
- scaleEnabled: _scaleEnabled,
- ),
- child: CustomPaint(
- painter: GesturePainter2(
- zoom: _zoom,
- offset: _offset,
- scaleEnabled: _scaleEnabled,
- ),
- )
- ),
- )
- ]
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement