Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. void _handleScaleStart(ScaleStartDetails details) {
  2. setState(() {
  3. _startingFocalPoint = details.focalPoint;
  4. _previousOffset = _offset;
  5. _previousZoom = _zoom;
  6. });
  7. }
  8.  
  9.  
  10.  
  11. void _handleScaleUpdate(ScaleUpdateDetails details) {
  12. setState(() {
  13. _zoom = _previousZoom * details.scale;
  14.  
  15. // Ensure that item under the focal point stays in the same place despite zooming
  16. final Offset normalizedOffset = (_startingFocalPoint - _previousOffset) / _previousZoom;
  17. _offset = details.focalPoint - normalizedOffset * _zoom;
  18. });
  19. }
  20.  
  21.  
  22.  
  23.  
  24.  
  25. @override
  26. Widget build(BuildContext context) {
  27. return Stack(
  28. fit: StackFit.expand,
  29. children: <Widget>[
  30. GestureDetector(
  31. onScaleStart: _scaleEnabled ? _handleScaleStart : null,
  32. onScaleUpdate: _scaleEnabled ? _handleScaleUpdate : null,
  33. child: CustomPaint(
  34. painter: _GesturePainter(
  35. zoom: _zoom,
  36. offset: _offset,
  37. scaleEnabled: _scaleEnabled,
  38. ),
  39. child: CustomPaint(
  40. painter: GesturePainter2(
  41. zoom: _zoom,
  42. offset: _offset,
  43. scaleEnabled: _scaleEnabled,
  44. ),
  45. )
  46. ),
  47. )
  48. ]
  49. );
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement