• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Duit-Foundation / duit_kernel / 20698616575

04 Jan 2026 08:22PM UTC coverage: 76.286% (-0.4%) from 76.636%
20698616575

Pull #51

github

web-flow
Merge 9c1841ec3 into 9c331752d
Pull Request #51: feat: Add ViewModel capability

9 of 25 new or added lines in 4 files covered. (36.0%)

2 existing lines in 2 files now uncovered.

1779 of 2332 relevant lines covered (76.29%)

4.86 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

60.0
/lib/src/capabilities/ui_controller_capability.dart
1
import "package:duit_kernel/duit_kernel.dart";
2
import "package:duit_kernel/src/capabilities/driver_ref.dart";
3
import "package:meta/meta.dart";
4

5
/// Mixin that provides an interface for managing and interacting with UI element controllers
6
/// in the Duit driver.
7
///
8
/// Classes that mix in [UIControllerCapabilityDelegate] are expected to implement
9
/// logic for tracking, attaching, detaching, and updating UI controllers (typically wrapping
10
/// widgets, inputs, or other interactive elements).
11
///
12
/// By default, all methods throw [MissingCapabilityMethodImplementation] if not overridden, enforcing
13
/// that concrete platform or application drivers provide required behaviors.
14
///
15
/// Typical responsibilities include:
16
///   - Mapping UI controller IDs to their active controller instances
17
///   - Attaching/detaching controllers dynamically as UI is built or disposed
18
///   - Applying state and attribute updates received from the server or driver logic
19
///   - Exposing helpers to query or enumerate attached controllers
20
mixin UIControllerCapabilityDelegate implements DriverRefHolder {
21
  late final UIDriver _driver;
22

NEW
23
  @override
×
24
  @protected
NEW
25
  UIDriver get driver => _driver;
×
26

NEW
27
  @override
×
NEW
28
  void linkDriver(UIDriver driver) => _driver = driver;
×
29

30
  /// Attaches a UI element controller to the driver.
31
  ///
32
  /// Called when a new UI element or interactive widget is created and
33
  /// needs to be tracked or managed by the driver. The [id] should be a
34
  /// unique identifier for the controller within the driver context.
35
  ///
36
  /// The [controller] instance provides control over state, events, and
37
  /// properties of the associated UI element.
38
  ///
39
  /// Implementations are responsible for tracking the mapping and making the
40
  /// controller available for updates and lookups using [getController].
41
  ///
42
  /// Throws [MissingCapabilityMethodImplementation] if not overridden.
43
  @mustBeOverridden
4✔
44
  void attachController(
45
    String id,
46
    UIElementController controller,
47
  ) =>
48
      throw const MissingCapabilityMethodImplementation(
49
        "attachController",
50
        "UIControllerCapabilityDelegate",
51
      );
52

53
  /// Detaches the UI element controller associated with the given [id].
54
  ///
55
  /// Called when a UI element or interactive widget is disposed or no longer
56
  /// needs to be managed by the driver. The implementation should remove any
57
  /// references to the controller to allow for proper garbage collection and to
58
  /// prevent memory leaks.
59
  ///
60
  /// If the controller for the given [id] does not exist, this method may be a no-op.
61
  ///
62
  /// Throws [MissingCapabilityMethodImplementation] if not overridden.
63
  @mustBeOverridden
4✔
64
  void detachController(String id) =>
65
      throw const MissingCapabilityMethodImplementation(
66
        "detachController",
67
        "UIControllerCapabilityDelegate",
68
      );
69

70
  /// Returns the [UIElementController] associated with the given [id], or `null` if
71
  /// no such controller is currently attached to the driver.
72
  ///
73
  /// The [id] should match the unique identifier provided when [attachController] was called.
74
  ///
75
  /// This method enables lookups for dynamic access to element state, imperative methods,
76
  /// or for integrating with widgets that need to control or listen to specific UI element controllers.
77
  ///
78
  /// Throws [MissingCapabilityMethodImplementation] if not overridden.
79
  @mustBeOverridden
4✔
80
  UIElementController? getController(String id) =>
81
      throw const MissingCapabilityMethodImplementation(
82
        "getController",
83
        "UIControllerCapabilityDelegate",
84
      );
85

86
  /// Updates the attributes (properties) of the UI element controller identified by [controllerId].
87
  ///
88
  /// The [json] parameter is a `Map<String, dynamic>` containing key-value pairs representing
89
  /// the attributes to update on the specified controller. Implementations should deserialize
90
  /// or assign these values as appropriate for the UI element's state, triggering any necessary
91
  /// UI updates, re-rendering, or side effects.
92
  ///
93
  /// - If the controller with [controllerId] does not exist, this method may throw,
94
  ///   be a no-op, or handle the situation gracefully depending on implementation.
95
  /// - Values in [json] are expected to match the schema or interface supported by
96
  ///   the associated [UIElementController].
97
  ///
98
  /// Throws [MissingCapabilityMethodImplementation] if not overridden.
99
  @mustBeOverridden
4✔
100
  Future<void> updateAttributes(
101
    String controllerId,
102
    Map<String, dynamic> json,
103
  ) =>
104
      throw const MissingCapabilityMethodImplementation(
105
        "updateAttributes",
106
        "UIControllerCapabilityDelegate",
107
      );
108

109
  /// Returns the number of currently attached [UIElementController]s managed by this delegate.
110
  ///
111
  /// This getter should provide a count of all active UI element controllers that have been
112
  /// attached via [attachController], and not subsequently detached via [detachController].
113
  ///
114
  /// The value is useful for diagnostics, debugging, or for systems needing to monitor or
115
  /// iterate over all registered UI controllers at runtime.
116
  ///
117
  /// Throws [MissingCapabilityMethodImplementation] if not overridden.
118
  @mustBeOverridden
4✔
119
  int get controllersCount => throw const MissingCapabilityMethodImplementation(
120
        "controllersCount",
121
        "UIControllerCapabilityDelegate",
122
      );
123

124
  /// Called to clean up any external resources, subscriptions, or handlers
125
  /// typically when a delegate is being disposed of or detached. Implementations
126
  /// should ensure all open streams or event sources are closed.
127
  ///
128
  /// This method must be overridden by implementers.
129
  ///
130
  /// Throws [MissingCapabilityMethodImplementation] by default.
131
  @mustBeOverridden
4✔
132
  void releaseResources() => throw const MissingCapabilityMethodImplementation(
133
        "releaseResources",
134
        "UIControllerCapabilityDelegate",
135
      );
136
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc