Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#15 fixed. #68

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class _MyHomePageState extends State<MyHomePage> {
),
)
: null,
scaleLimit: 3.0,
),
),
),
Expand Down
7 changes: 7 additions & 0 deletions lib/src/crop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Crop extends StatefulWidget {
final BoxShape shape;
final ValueChanged<MatrixDecomposition>? onChanged;
final Duration animationDuration;
final double? scaleLimit;

const Crop({
Key? key,
Expand All @@ -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);

Expand Down Expand Up @@ -71,11 +73,13 @@ class _CropState extends State<Crop> 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
Expand Down Expand Up @@ -192,6 +196,9 @@ class _CropState extends State<Crop> 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;

Expand Down