native_image_cropper_platform_interface 0.2.0 copy "native_image_cropper_platform_interface: ^0.2.0" to clipboard
native_image_cropper_platform_interface: ^0.2.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) {
      throw NativeImageCropperException(e.code, e.message);
    }
  }

  @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) {
      throw NativeImageCropperException(e.code, e.message);
    }
  }
}
2
likes
140
pub points
47%
popularity

Publisher

verified publishercosee.biz

A common platform interface for the native_image_cropper plugin.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on native_image_cropper_platform_interface