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

Duit-Foundation / duit_kernel / 20529564277

26 Dec 2025 09:17PM UTC coverage: 76.029% (-0.4%) from 76.46%
20529564277

Pull #50

github

web-flow
Merge 68b9a029f into 08552f056
Pull Request #50: feat: Migration to capability-based API pt1

7 of 21 new or added lines in 3 files covered. (33.33%)

1754 of 2307 relevant lines covered (76.03%)

4.74 hits per line

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

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

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

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

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

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

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

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

116
  /// Called to clean up any external resources, subscriptions, or handlers
117
  /// typically when a delegate is being disposed of or detached. Implementations
118
  /// should ensure all open streams or event sources are closed.
119
  ///
120
  /// This method must be overridden by implementers.
121
  ///
122
  /// Throws [MissingCapabilityMethodImplementation] by default.
NEW
123
  @mustBeOverridden
×
124
  void releaseResources() => throw const MissingCapabilityMethodImplementation(
125
        "releaseResources",
126
        "UIControllerCapabilityDelegate",
127
      );
128
}
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