Skip to main content

ViewModelCapabilityDelegate

A mixin that provides capabilities for managing and interacting with views in the Duit UI system.

Allows classes to interact with drivers, respond to UI events, and manage view lifecycle.

Methods​

eventStream​

Stream<UIDriverEvent> get eventStream;

Stream of driver events (UIDriverEvent) managed by the delegate.

Used for listening to driver events and updating state in response.

buildContext​

BuildContext get buildContext;

The current BuildContext associated with the driver.

context (setter)​

set context(BuildContext value);

Sets the current BuildContext for the delegate.

addUIDriverEvent​

void addUIDriverEvent(UIDriverEvent event);

Adds a UIDriverEvent to the event stream.

addUIDriverError​

void addUIDriverError(Object error, [StackTrace? stackTrace]);

Reports an error that occurred in the driver context.

notifyWidgetDisplayStateChanged​

void notifyWidgetDisplayStateChanged(String viewTag, int state);

Notifies the driver about widget display state changes.

Parameters:

  • viewTag — widget tag
  • state — new state (0 = not visible, 1 = visible and displayed)

isWidgetReady​

bool isWidgetReady(String viewTag);

Checks if a widget is ready to be displayed.

prepareLayout​

Future<DuitView?> prepareLayout(Map<String, dynamic> json);

Prepares and validates a layout configuration from JSON, returning a DuitView instance.

Parameters:

  • json — layout structure (widgets, properties, relationships)

Returns: DuitView for further use or null for invalid layout.

currentView​

DuitView? get currentView;

Returns the currently displayed view.

releaseResources​

void releaseResources();

Releases delegate resources.

Usage Example​

final class MyViewManager with ViewModelCapabilityDelegate {
final _eventController = StreamController<UIDriverEvent>.broadcast();
BuildContext? _context;
DuitView? _currentView;


Stream<UIDriverEvent> get eventStream => _eventController.stream;


BuildContext get buildContext => _context!;


set context(BuildContext value) => _context = value;


void addUIDriverEvent(UIDriverEvent event) {
_eventController.add(event);
}


void addUIDriverError(Object error, [StackTrace? stackTrace]) {
_eventController.addError(error, stackTrace);
}


Future<DuitView?> prepareLayout(Map<String, dynamic> json) async {
// Parse and prepare layout
return _currentView;
}


DuitView? get currentView => _currentView;


void releaseResources() {
_eventController.close();
}

// ... other methods
}