Skip to content
Open
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
28 changes: 20 additions & 8 deletions lib/src/crop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Crop extends StatefulWidget {
final double maximumScale;
final bool alwaysShowGrid;
final ImageErrorListener? onImageError;
final bool flip;

const Crop({
Key? key,
Expand All @@ -27,6 +28,7 @@ class Crop extends StatefulWidget {
this.maximumScale = 2.0,
this.alwaysShowGrid = false,
this.onImageError,
this.flip = false,
}) : super(key: key);

Crop.file(
Expand All @@ -37,6 +39,7 @@ class Crop extends StatefulWidget {
this.maximumScale = 2.0,
this.alwaysShowGrid = false,
this.onImageError,
this.flip = false,
}) : image = FileImage(file, scale: scale),
super(key: key);

Expand All @@ -49,6 +52,7 @@ class Crop extends StatefulWidget {
this.maximumScale = 2.0,
this.alwaysShowGrid = false,
this.onImageError,
this.flip = false,
}) : image = AssetImage(assetName, bundle: bundle, package: package),
super(key: key);

Expand All @@ -72,6 +76,7 @@ class CropState extends State<Crop> with TickerProviderStateMixin, Drag {
Offset _lastFocalPoint = Offset.zero;
_CropAction _action = _CropAction.none;
_CropHandleSide _handle = _CropHandleSide.none;
bool flip = false;

late double _startScale;
late Rect _startView;
Expand Down Expand Up @@ -111,6 +116,7 @@ class CropState extends State<Crop> with TickerProviderStateMixin, Drag {
)..addListener(() => setState(() {}));
_settleController = AnimationController(vsync: this)
..addListener(_settleAnimationChanged);
flip = widget.flip;
}

@override
Expand All @@ -136,6 +142,8 @@ class CropState extends State<Crop> with TickerProviderStateMixin, Drag {
void didUpdateWidget(Crop oldWidget) {
super.didUpdateWidget(oldWidget);

flip = widget.flip;
debugPrint('didUpdateWidget flip: $flip');
if (widget.image != oldWidget.image) {
_getImage();
} else if (widget.aspectRatio != oldWidget.aspectRatio) {
Expand Down Expand Up @@ -184,14 +192,18 @@ class CropState extends State<Crop> with TickerProviderStateMixin, Drag {
onScaleStart: _isEnabled ? _handleScaleStart : null,
onScaleUpdate: _isEnabled ? _handleScaleUpdate : null,
onScaleEnd: _isEnabled ? _handleScaleEnd : null,
child: CustomPaint(
painter: _CropPainter(
image: _image,
ratio: _ratio,
view: _view,
area: _area,
scale: _scale,
active: _activeController.value,
child: Transform(
alignment: Alignment.center,
transform: Matrix4.rotationY(flip ? pi : 0),
child: CustomPaint(
painter: _CropPainter(
image: _image,
ratio: _ratio,
view: _view,
area: _area,
scale: _scale,
active: _activeController.value,
),
),
),
),
Expand Down