How do I send data from iOS to Dart in Flutter?
In Nutrient Flutter SDK 6, you no longer need to edit the plugin or wire up a FlutterMethodChannel to send data from native code back to Dart. Use platform adapters to bridge native callbacks into your Dart code:
- Cross-platform events — Listen to most document, page, annotation, and form events through the typed
controller.eventsstream. You don’t need native code for these events. - Platform-only events — Use platform-specific streams for events that don’t have a cross-platform equivalent, such as
iosEventsonIOSAdapterandandroidEventsonAndroidAdapter. - Custom native callbacks — Subclass the platform adapter to observe native APIs, such as notifications or delegate methods, and emit your own events to Dart. The adapter provides access to the native
PSPDFViewControlleron iOS andPdfFragmenton Android through its escape-hatch accessors.
The following example listens for page changes with a single subscription:
NutrientDocumentView( documentPath: documentPath, onControllerReady: (controller) { controller.events.pageChanged.listen((event) { print('Page changed to ${event.pageIndex}'); }); },)For a walkthrough of subclassing an adapter and emitting custom events from native code, refer to the platform adapters guide and the event listeners section in the platform adapter usage patterns guide.
The previous approach — editing PspdfkitPlugin.m and registering callbacks on the Pspdfkit class through a method channel — is part of the legacy method-channel API. You no longer need it.