Skip to main content

UIControllerCapabilityDelegate

A mixin that provides an interface for managing UI element controllers in the Duit driver.

Classes using this delegate must implement logic for tracking, attaching, detaching, and updating UI controllers.

Methods​

attachController​

void attachController(String id, UIElementController controller);

Attaches a UI controller to the driver.

Called when a new UI element or interactive widget is created that needs to be tracked by the driver.

Parameters:

detachController​

void detachController(String id);

Detaches the UI controller with the specified identifier.

Called when a UI element is removed to prevent memory leaks.

getController​

UIElementController? getController(String id);

Returns the UIElementController associated with the specified identifier, or null.

updateAttributes​

Future<void> updateAttributes(
String controllerId,
Map<String, dynamic> json,
);

Updates attributes of the UI controller with the specified identifier.

Parameters:

  • controllerId — controller identifier
  • json — key-value map with attributes to update

controllersCount​

int get controllersCount;

Returns the number of controllers attached to the delegate.

Useful for diagnostics and debugging.

releaseResources​

void releaseResources();

Releases delegate resources.

Typical Responsibilities​

  • Mapping controller identifiers to their active instances
  • Dynamically attaching/detaching controllers when building or disposing UI
  • Applying state and attribute updates from the server
  • Providing methods for querying or enumerating attached controllers

Implementation Example​

final class MyControllerManager with UIControllerCapabilityDelegate {
final _controllers = <String, UIElementController>{};


void attachController(String id, UIElementController controller) {
_controllers[id] = controller;
}


void detachController(String id) {
_controllers.remove(id)?.dispose();
}


UIElementController? getController(String id) => _controllers[id];


Future<void> updateAttributes(
String controllerId,
Map<String, dynamic> json,
) async {
_controllers[controllerId]?.updateState(json);
}


int get controllersCount => _controllers.length;


void releaseResources() {
for (final controller in _controllers.values) {
controller.dispose();
}
_controllers.clear();
}
}