How hnvn/flutter_image_cropper works
Project Type and Purpose
• This is a multi‐platform Flutter plugin (package) that exposes a single Dart API—ImageCropper().cropImage(...)—but delegates actual image cropping to three separate native libraries:
• Android – uCrop (Java/Kotlin)
• iOS – TOCropViewController (Objective-C/Swift)
• Web – Cropper.js (JavaScript)
• The repo is arranged as a Flutter “federated plugin” with three packages:
• image_cropper_platform_interface – the common Dart interface and MethodChannel abstraction
• image_cropper – the Android + iOS implementation
• image_cropper_for_web – the Web implementation
• plus example apps under each package’s example/ folder.
High-Level File Structure
• Top‐level packages:
• image_cropper_platform_interface/
• image_cropper/ (contains native android/ and ios/ folders plus the host Dart wrapper)
• image_cropper_for_web/
• Each package has its own pubspec.yaml, README.md, and tests/examples.
Key Architectural Patterns
• Federated Plugin: a “platform interface” package defines an abstract API and registers implementations by platform.
• MethodChannel: Dart ↔ native messaging on Android/iOS
• JS Interop: Dart ↔ JavaScript interop on Web
• Delegation Pattern: the Dart facade (ImageCropper in image_cropper.dart) delegates to the platform interface, which finds the right platform implementation.
Main Components
• Flutter Application Layer
• Your Flutter UI code (example or host app)
• image_cropper Dart API façade
• Platform Interface Layer
• ImageCropperPlatform abstract class (in image_cropper_platform_interface)
• MethodChannel dispatcher (default implementation)
• Android Native Layer
• MethodChannelImageCropper (Java)
• uCrop library (external)
• AndroidManifest, Gradle build system
• iOS Native Layer
• FLTImageCropperPlugin (Objective-C/Swift)
• TOCropViewController (external)
• CocoaPods / Xcode project
• Web Layer
• ImageCropperForWeb (Dart)
• cropperjs (external JS)
• dart:js interop
• Storage / File System
• Temporary cache on Android (cache dir)
• NSTemporaryDirectory on iOS
Architectural Patterns & Principles to Highlight
• Separation of concerns (Dart API vs. native code vs. JS code)
• Platform‐agnostic interface vs. platform‐specific implementations
• Plugin registration and federated plugin pattern
Essential Elements
• Clear, descriptive labels for each component/class