NutrientController class
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 extending NutrientController:
abstract class MyController extends NutrientController {
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
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- isDisposed → bool
-
Whether the controller has been disposed.
no setter
- isReady → bool
-
Whether the controller is ready for use.
no setter
- 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.
-
dispose(
) → Future< void> - Dispose of this controller and release resources.
-
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.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited