showCropUI static method

Future<CropRect?> showCropUI(
  1. BuildContext context,
  2. String imagePath,
  3. CropOptions? cropOptions
)

Show the interactive crop UI and return the selected crop rectangle

Implementation

static Future<CropRect?> showCropUI(
  BuildContext context,
  String imagePath,
  CropOptions? cropOptions,
) async {
  if (!context.mounted) return null;

  CropRect? selectedCropRect;

  final result = await Navigator.of(context).push<CropRect>(
    MaterialPageRoute(
      builder: (context) => CropUI(
        imagePath: imagePath,
        initialCropOptions: cropOptions,
        onCropChanged: (cropRect) {
          selectedCropRect = cropRect;
        },
        onConfirm: () {
          Navigator.of(context).pop(selectedCropRect);
        },
        onCancel: () {
          Navigator.of(context).pop(null);
        },
      ),
      fullscreenDialog: true,
    ),
  );

  return result;
}