diff --git a/example/lib/main.dart b/example/lib/main.dart index 518dda9..1edcad2 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -138,6 +138,7 @@ class _MyHomePageState extends State { ), ) : null, + scaleLimit: 3.0, ), ), ), diff --git a/lib/src/crop.dart b/lib/src/crop.dart index 3f2dc0f..c495998 100644 --- a/lib/src/crop.dart +++ b/lib/src/crop.dart @@ -23,6 +23,7 @@ class Crop extends StatefulWidget { final BoxShape shape; final ValueChanged? onChanged; final Duration animationDuration; + final double? scaleLimit; const Crop({ Key? key, @@ -38,6 +39,7 @@ class Crop extends StatefulWidget { this.interactive = true, this.shape = BoxShape.rectangle, this.onChanged, + this.scaleLimit, this.animationDuration = const Duration(milliseconds: 200), }) : super(key: key); @@ -71,11 +73,13 @@ class _CropState extends State with TickerProviderStateMixin { final _repaintBoundaryKey = GlobalKey(); double _previousScale = 1; + Offset _previousOffset = Offset.zero; Offset _startOffset = Offset.zero; Offset _endOffset = Offset.zero; double _previousGestureRotation = 0.0; + /// Store the pointer count (finger involved to perform scaling). /// /// This is used to compare with the value in @@ -192,6 +196,9 @@ class _CropState extends State with TickerProviderStateMixin { widget.controller._offset += details.focalPoint - _previousOffset; _previousOffset = details.focalPoint; widget.controller._scale = _previousScale * details.scale; + if(widget.scaleLimit != null && widget.controller._scale > widget.scaleLimit!){ + widget.controller._scale = widget.scaleLimit!; + } _startOffset = widget.controller._offset; _endOffset = widget.controller._offset;