NutrientPlatformAdapter class abstract

Platform adapter interface for extending Nutrient functionality.

Platform adapters provide lifecycle hooks and access to native SDK instances, enabling deep customization without forking the plugin.

Overview

The core plugin provides:

  • Document display via NutrientView
  • Native instance access via platform-specific adapters

Platform adapters provide:

  • Lifecycle hooks (view creation, document loading, cleanup)
  • Direct access to native SDK instances
  • Custom event handling and business logic

Implementation

Extend the platform-specific base adapter:

Android (JNI Bindings)

class MyAndroidAdapter extends AndroidAdapter {
  @override
  Future<void> onFragmentAttached(
    PdfUiFragment fragment,
    Context context,
  ) async {
    // Access fragment methods through JNI
    final config = fragment.getConfiguration();
  }

  @override
  Future<void> onDocumentLoaded(
    PdfDocument document,
    PdfFragment pdfFragment,
  ) async {
    // Access document properties
    final pageCount = document.getPageCount();
  }

  @override
  Future<void> onFragmentDetached() async {
    // Clean up resources
  }
}

iOS (FFI Bindings)

class MyIOSAdapter extends IOSAdapter {
  @override
  Future<void> onPlatformViewCreated(NutrientViewHandle handle) async {
    await super.onPlatformViewCreated(handle);
    // Access iOS-specific APIs through handle
    // Implementation depends on iOS adapter structure
  }
}

Web (JavaScript Interop)

class MyWebAdapter extends NutrientWebAdapter {
  @override
  Future<void> configureLoad(
    NutrientViewHandle handle,
    Map<String, dynamic> config,
  ) async {
    await super.configureLoad(handle, config);
    config['layoutMode'] = 'SINGLE';
    config['theme'] = 'DARK';
  }

  @override
  Future<void> onPlatformViewCreated(NutrientViewHandle handle) async {
    await super.onPlatformViewCreated(handle);
    final instance = getInstance(handle);
    // Use instance to access Web SDK APIs
  }
}

Registration

Register adapters during initialization:

await Nutrient.initialize(
  licenseKey: 'YOUR_LICENSE_KEY',
  androidAdapter: MyAndroidAdapter(),
  iosAdapter: MyIOSAdapter(),
  webAdapter: MyWebAdapter(),
);

Error handling in lifecycle hooks

The lifecycle hooks (onPlatformViewCreated, the platform-specific onFragmentReady / onViewControllerReady / onInstanceLoaded, and the configure* hooks) are Future<void> and may throw. The SDK awaits each hook and catches any error so a failing hook can't tear the view down — the error is logged and the view still renders. Hooks are not retried, so a hook that needs to recover from a failure must handle it itself (wrap the risky work in its own try/catch).

Implementers

Constructors

NutrientPlatformAdapter()

Properties

hashCode int
The hash code for this object.
no setterinherited
platform TargetPlatform
The platform this adapter targets.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

dispose() Future<void>
Dispose of this adapter and clean up resources.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onPlatformViewCreated(NutrientViewHandle handle) Future<void>
Called when the platform view is created.
openDocument(String path, {String? password}) Future<NutrientDocumentInterface>
Opens a document without displaying a viewer (headless mode).
openDocumentFromBytes(Uint8List bytes, {String? password}) Future<NutrientDocumentInterface>
Opens a document from in-memory bytes without a viewer (headless).
processAnnotations(String sourcePath, AnnotationType type, AnnotationProcessingMode mode, String destinationPath) Future<bool>
Processes the annotations of the document at sourcePath and writes the result to destinationPath, mirroring the legacy SDK's annotation processing.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited