cropImage method
Implementation
Future<File?> cropImage(String imagePath) async {
try {
if (Platform.isIOS) {
// Wait on iOS to allow the previous fullscreen view (Camera/Gallery) to fully settle.
// This ensures TOCropViewController measures the Safe Area correctly.
await Future.delayed(const Duration(milliseconds: 1000));
}
final cropped = await ImageCropper().cropImage(
sourcePath: imagePath,
uiSettings: [
AndroidUiSettings(
toolbarTitle: 'Crop Image',
toolbarColor: Colors.black,
toolbarWidgetColor: Colors.white,
initAspectRatio: CropAspectRatioPreset.original,
lockAspectRatio: false,
),
IOSUiSettings(
title: 'Crop Image',
),
],
);
return cropped != null ? File(cropped.path) : null;
} catch (e) {
debugPrint('PixelToPdfService: cropImage error: $e');
return null;
}
}