NutrientController class abstract
Base class for Nutrient controllers.
This is the foundation for the adapter-as-controller pattern. Platform adapters extend this class, allowing them to serve as both platform adapters and controllers.
Adapter-as-Controller Pattern
Instead of having separate adapter and controller objects, the adapter itself serves as the controller:
NutrientController (this class)
↑ extends
PlatformAdapter (e.g., AndroidAdapter, IOSAdapter, NutrientWebAdapter)
↑ extends
YourAdapter ─────► implements YourController
│
└── The adapter IS the controller
Creating a Custom Controller
- Define your controller interface implementing NutrientControllerInterface:
abstract class MyController implements NutrientControllerInterface {
Future<int> getPageCount();
Future<int> getCurrentPageIndex();
}
- Have your platform adapters implement your controller:
class MyAndroidAdapter extends AndroidAdapter implements MyController {
PdfDocument? _document;
@override
Future<int> getPageCount() => Future.value(_document?.getPageCount() ?? 0);
}
- Use typed controller access in your view:
NutrientView<MyController>(
documentPath: 'document.pdf',
onControllerReady: (controller) async {
// Type-safe access to your APIs
final pageCount = await controller.getPageCount();
},
)
Lifecycle
The controller goes through these lifecycle states:
- Created - Controller instance exists but view not ready
- Ready - View is created and isReady is true
- Disposed - Controller is disposed (isDisposed is true)
Lifecycle Methods
- Implemented types
Constructors
Properties
- document → NutrientDocumentInterface
-
The open PDF document and its document-level operations.
no setteroverride
-
events
→ Stream<
NutrientEvent> -
A broadcast stream of cross-platform typed SDK events.
no setteroverride
- hashCode → int
-
The hash code for this object.
no setterinherited
- isDisposed → bool
-
Whether the controller has been disposed.
no setteroverride
- isReady → bool
-
Whether the controller is ready for use.
no setteroverride
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- viewHandle → NutrientViewHandle?
-
The internal view handle for accessing native instances.
no setter
Methods
-
attachViewHandle(
NutrientViewHandle viewHandle) → void - Attach the view handle to this controller.
-
consumeViewAttached(
) → bool - For platform adapters: atomically check-and-clear the view-attached flag.
-
convertPdfPointToViewPoint(
int pageIndex, Offset point) → Future< Offset> -
Converts a point from PDF page coordinates to the page view's
coordinate space.
override
-
convertViewPointToPdfPoint(
int pageIndex, Offset point) → Future< Offset> -
Converts a point from the page view's coordinate space to PDF page
coordinates.
override
-
dispose(
) → Future< void> -
Dispose of this controller and release resources.
override
-
emitEvent(
NutrientEvent event) → void - Emits a cross-platform event to all events subscribers.
-
enterAnnotationCreationMode(
[AnnotationTool? annotationTool]) → Future< bool?> -
Enters annotation creation mode for the specified
annotationTool.override -
exitAnnotationCreationMode(
) → Future< bool?> -
Exits annotation creation mode and returns to normal viewer
interaction.
override
-
getVisibleRect(
int pageIndex) → Future< Rect> -
Gets the visible rect of the given page.
override
-
getZoomScale(
int pageIndex) → Future< double> -
Gets the current zoom scale of the given page.
override
-
markReady(
) → Future< void> - Mark the controller as ready for use.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onReady(
) → Future< void> - Called when the controller becomes ready.
-
setAnnotationConfigurations(
Map< String, dynamic> configurations) → Future<bool> -
Sets annotation preset configurations for the viewer's annotation toolbar.
override
-
setAnnotationEditingToolbarItems(
List< AnnotationEditingItem> items) → Future<void> -
No-op default — annotation editing toolbar customization is opt-in per
platform (Web/Android/iOS adapters override this).
override
-
setAnnotationMenuConfiguration(
Map< String, dynamic> configuration) → Future<bool> -
Configures the annotation context menu (items to show, disable, or hide).
override
-
setAnnotationToolbarItems(
List< AnnotationToolbarItem> items) → Future<void> -
No-op default — annotation creation toolbar customization is opt-in per
platform (Android/iOS adapters override this; Web routes annotation tools
through the main toolbar).
override
-
setMainToolbarItems(
List< ToolbarItem> items) → Future<void> -
No-op default — toolbar customization is opt-in per platform. The
Android/iOS/Web adapters override this; controllers that don't support it
simply ignore the request.
override
-
toString(
) → String -
A string representation of this object.
inherited
-
zoomToRect(
int pageIndex, Rect rect) → Future< void> -
Zooms to the given
recton the given page.override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited