Skip to content

Commit

Permalink
fix: respect initial size if specified when changing aspectRatio via …
Browse files Browse the repository at this point in the history
…controller (#170)
  • Loading branch information
chooyan-eng authored Dec 11, 2024
1 parent bbcd1f9 commit 05d2f61
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/src/widget/crop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ class _CropEditorState extends State<_CropEditor> {
/// detected image format with [widget.formatDetector]
ImageFormat? _detectedFormat;

double? _sizeCache;

@override
void initState() {
super.initState();
Expand All @@ -313,11 +315,11 @@ class _CropEditorState extends State<_CropEditor> {
_cropController.delegate = CropControllerDelegate()
..onCrop = _crop
..onChangeAspectRatio = (aspectRatio) {
_resizeWithSizeAndRatio(null, aspectRatio);
_resizeWithSizeAndRatio(_sizeCache, aspectRatio);
}
..onChangeWithCircleUi = (withCircleUi) {
_viewState = _readyState.copyWith(withCircleUi: withCircleUi);
_resizeWithSizeAndRatio(null, null);
_resizeWithSizeAndRatio(_sizeCache, null);
}
..onImageChanged = _resetImage
..onChangeCropRect = (newCropRect) {
Expand Down Expand Up @@ -474,6 +476,7 @@ class _CropEditorState extends State<_CropEditor> {
_resizeWithArea(builder.area);
case (WithSizeAndRatioInitialRectBuilder()):
_resizeWithSizeAndRatio(builder.size, builder.aspectRatio);
_sizeCache = builder.size;
default:
_resizeWithSizeAndRatio(null, widget.aspectRatio);
}
Expand Down

0 comments on commit 05d2f61

Please sign in to comment.