native_image_cropper_platform_interface 0.3.0 copy "native_image_cropper_platform_interface: ^0.3.0" to clipboard
native_image_cropper_platform_interface: ^0.3.0 copied to clipboard

A common platform interface for the native_image_cropper plugin.

example/lib/main.dart

import 'package:flutter/services.dart';
import 'package:native_image_cropper_platform_interface/native_image_cropper_platform_interface.dart';

final class NativeImageCropperExample extends NativeImageCropperPlatform {
  final MethodChannel _methodChannel = const MethodChannel(
    'biz.cosee/native_image_cropper_android',
  );

  static void registerWith() =>
      NativeImageCropperPlatform.instance = NativeImageCropperExample();

  @override
  Future<Uint8List> cropRect({
    required Uint8List bytes,
    required int x,
    required int y,
    required int width,
    required int height,
    ImageFormat format = ImageFormat.jpg,
  }) async {
    final arguments = {
      'bytes': bytes,
      'x': x,
      'y': y,
      'width': width,
      'height': height,
      'imageFormat': format.name,
    };
    try {
      final croppedImage = await _methodChannel.invokeMethod<Uint8List>(
        'cropRect',
        arguments,
      );
      if (croppedImage == null) {
        throw const NativeImageCropperException(
          'NullPointerException',
          'Method channel cropRect() returns null!',
        );
      }
      return croppedImage;
    } on PlatformException catch (e, stackTrace) {
      Error.throwWithStackTrace(
        NativeImageCropperException(e.code, e.message),
        stackTrace,
      );
    }
  }

  @override
  Future<Uint8List> cropOval({
    required Uint8List bytes,
    required int x,
    required int y,
    required int width,
    required int height,
    ImageFormat format = ImageFormat.jpg,
  }) async {
    final arguments = {
      'bytes': bytes,
      'x': x,
      'y': y,
      'width': width,
      'height': height,
      'imageFormat': format.name,
    };
    try {
      final croppedImage = await _methodChannel.invokeMethod<Uint8List>(
        'cropOval',
        arguments,
      );
      if (croppedImage == null) {
        throw const NativeImageCropperException(
          'NullPointerException',
          'Method channel cropOval() returns null!',
        );
      }
      return croppedImage;
    } on PlatformException catch (e, stackTrace) {
      Error.throwWithStackTrace(
        NativeImageCropperException(e.code, e.message),
        stackTrace,
      );
    }
  }
}
2
likes
160
points
2.61k
downloads

Documentation

API reference

Publisher

verified publishercosee.biz

Weekly Downloads

A common platform interface for the native_image_cropper plugin.

Homepage
Repository (GitHub)
View/report issues
Contributing

License

BSD-3-Clause (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on native_image_cropper_platform_interface