native_image_cropper 0.2.0 copy "native_image_cropper: ^0.2.0" to clipboard
native_image_cropper: ^0.2.0 copied to clipboard

A Flutter plugin for cropping images. Supports rectangular and circular cropping.

native_image_cropper #

pub package package publisher style license

A Flutter plugin which supports native circular and rectangular cropping.

Preview example

Features #

  • Better performance, since it is written in Kotlin/Swift
  • Usable without widget
  • Circular and rectangular cropping
  • Customizable drag points
  • Customizable crop mask
  • Customizable hit size

Usage #

Depend on it:

dependencies:
  native_image_cropper: ^0.1.1

Import it:

import 'package:native_image_cropper/native_image_cropper.dart';

Minimal example: #

Scaffold(
  body: CropPreview(
    bytes: imageData,
  ),
);

Customization options: #

final maskOptions = const MaskOptions(
  backgroundColor: Colors.black38,
  borderColor: Colors.grey,
  strokeWidth: 2,
  aspectRatio: 4 / 3,
  minSize: 0,
);

CropPreview(
  mode: CropMode.rect,
  dragPointSize: 20,
  hitSize: 20,
  maskOptions: maskOptions,
  dragPointBuilder: (size, position) {
    if (position == CropDragPointPosition.topLeft) {
      return CropDragPoint(size: size, color: Colors.red);
    }
    return CropDragPoint(size: size, color: Colors.blue);
  },
);

Crop an image: #

To crop an image you can pass a CropController to CropPreview:

final controller = CropController();

CropPreview(controller: controller, bytes: imageData);

final croppedBytes = await controller.crop();

or call it directly using MethodChannels:

final croppedBytes = await NativeImageCropper.cropRect(
  bytes: imageData,
  x: 0,
  y: 0,
  width: 500,
  height: 500,
);
final croppedBytes = await NativeImageCropper.cropOval(
  bytes: imageData,
  x: 0,
  y: 0,
  width: 500,
  height: 500,
);