How pspdfkit/pspdfkit-flutter works
Project type and purpose
• This is an open-source Flutter plugin (SDK) that embeds the PSPDFKit PDF engine into Flutter apps on Android, iOS, and Web.
• It provides a unified Dart API, platform channels (MethodChannel/Pigeon), and native/web adaptors to the underlying PSPDFKit binaries or WebAssembly.
File structure
• lib/: The Dart interface and platform-agnostic implementation.
• pigeons/: Pigeon IDL and generated platform API code (pspdfkit_api.g.dart).
• android/: Native Java/Kotlin plugin code, binds Dart calls to PSPDFKit Android SDK.
• ios/: Native Swift/Objective-C plugin code, binds Dart calls to PSPDFKit iOS SDK.
• web assets (under example/web and instructions in README): the PSPDFKit Web WASM and JS loader.
• example/: A sample Flutter application demonstrating plugin integration.
• test/: Unit tests for Dart code, mocks for Pigeon API, widget controller tests.
README for insights
• Confirms cross-platform support (Android, iOS, Web).
• Describes setup steps and the runtime flow: initializing Pspdfkit.initialize() → PspdfkitWidget → document loading → platform SDK.
Main components
a. Flutter App Layer
• Widgets (e.g., PspdfkitWidget, host app UI)
• Business logic (e.g., asset extraction, FutureBuilders)
b. Dart SDK Core (lib/pspdfkit_flutter.dart + lib/src/…)
• Public API surface (Pspdfkit, PspdfkitWidgetController)
• MethodChannel or Pigeon channel handlers (pspdfkit_flutter_method_channel.dart, pspdfkit_flutter_api_impl.dart)
c. Pigeon-Generated API (pigeons/ and lib/src/api/pspdfkit_api.g.dart)
• Strongly typed messages and callbacks
d. Platform Channels
• MethodChannel (Android/iOS) & JS interop (Web)
e. Platform-Specific Plugin Code
• Android: Java/Kotlin classes under android/src/main/java/com/pspdfkit/flutter/pspdfkit
• iOS: Swift/ObjC under ios/Classes
• Web: JavaScript/WASM assets loaded via <script src="assets/pspdfkit.js">
f. Underlying PSPDFKit SDK
• Android AAR/native libraries
• iOS frameworks
• WebAssembly modules + JS glue
g. External Dependencies
• Flutter engine
• Gradle/Maven (Android build)
• CocoaPods (iOS build)
• Web server serving WASM with correct MIME
h. Example App
Relationships & Interactions
• SDK API → sends message over Pigeon/MethodChannel
• Platform channel → dispatch to Android/iOS/Web plugin code
• Plugin code → invokes PSPDFKit native SDK or WASM
• Results/events → bubble up via the same channel back to Dart → update UI
Architectural patterns & design principles
• Layered architecture: UI layer, SDK core, platform adaptors, native libraries
• Pigeon for type-safe channel calls
• Platform interface abstraction: Dart defines an interface (PspdfkitFlutterPlatform), implementations are registered per platform (Android, iOS, Web)
• Separation of concerns:
· UI vs document processing vs native binding
· Cross-platform vs platform-specific code
Essential elements to capture
• Public Dart API → MethodChannel/Pigeon layer → platform code → native/Web SDK
• Initialization phase (Pspdfkit.initialize) and document display (PspdfkitWidget)
• Asset loading (local file system on mobile, WASM served over HTTP on Web)
• Event callbacks (annotation events, form submissions, analytics)