Skip to content

Commit

Permalink
fix: upgrade to crop_your_image 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
inpt333 committed Jan 6, 2025
1 parent b889579 commit 21fa254
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
13 changes: 8 additions & 5 deletions lib/presentation/widgets/image_crop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:flutter/material.dart';

class ImageCrop extends StatefulWidget {
final Uint8List imageData;
final ValueSetter<Uint8List>? onCrop;
final ValueSetter<Uint8List?>? onCrop;

const ImageCrop({super.key, required this.imageData, this.onCrop});

Expand Down Expand Up @@ -35,13 +35,16 @@ class ImageCropState extends State<ImageCrop> {
controller: _controller,
image: imageData,
aspectRatio: 1,
initialSize: 0.7,
radius: 20,
interactive: true,
withCircleUi: true,
progressIndicator: const Center(child: CircularProgressIndicator()),
progressIndicator: const CircularProgressIndicator(),
onCropped: (result) {
if (widget.onCrop != null) {
widget.onCrop!(result);
switch (result) {
case CropSuccess(:final croppedImage):
widget.onCrop?.call(croppedImage);
case CropFailure():
widget.onCrop?.call(null);
}
},
),
Expand Down
3 changes: 2 additions & 1 deletion lib/presentation/widgets/image_form_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ class _ImageFormFieldState extends FormFieldState<XFile> {
builder: (BuildContext context) => Dialog.fullscreen(
child: ImageCrop(
imageData: imageData,
onCrop: (value) => Navigator.pop(context, XFile.fromData(value)),
onCrop: (value) => Navigator.pop(
context, value != null ? XFile.fromData(value) : null),
)));
}

Expand Down

0 comments on commit 21fa254

Please sign in to comment.