• 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

69.23
/lib/src/capabilities/viewmodel_capability.dart
1
import "package:duit_kernel/duit_kernel.dart";
2
import "package:duit_kernel/src/capabilities/driver_ref.dart";
3
import "package:flutter/widgets.dart";
4
import "package:meta/meta.dart";
5

6
/// A mixin that provides capabilities for managing and interacting with
7
/// views in the Duit UI system. Classes that mix in this delegate should
8
/// provide concrete implementations for handling driver events, widget
9
/// build context, error reporting, and display state changes.
10
///
11
/// Implementing this mixin allows a class to interact with [UIDriver]s,
12
/// respond to UI events, and manage view lifecycle updates in a
13
/// decoupled, extensible manner.
14
mixin ViewModelCapabilityDelegate implements DriverRefHolder {
15
  late final UIDriver _driver;
16

NEW
17
  @override
×
18
  @protected
NEW
19
  UIDriver get driver => _driver;
×
20

NEW
21
  @override
×
NEW
22
  void linkDriver(UIDriver driver) => _driver = driver;
×
23
  /// A stream of [UIDriverEvent]s that this delegate manages or receives.
24
  ///
25
  /// Implementors must provide access to a broadcast stream (or similar)
26
  /// that emits UI driver events as they occur in the view layer, such as
27
  /// UI interactions, state changes, or system notifications.
28
  ///
29
  /// This is typically used for listening to driver-originated events and
30
  /// updating state or triggering additional actions in response.
31
  ///
32
  /// Throws [MissingCapabilityMethodImplementation] if not overridden.
33
  @mustBeOverridden
4✔
34
  Stream<UIDriverEvent> get eventStream =>
35
      throw const MissingCapabilityMethodImplementation(
36
        "eventStream",
37
        "ViewModelCapabilityDelegate",
38
      );
39

40
  /// The build context associated with the UI driver.
41
  @mustBeOverridden
4✔
42
  BuildContext get buildContext =>
43
      throw const MissingCapabilityMethodImplementation(
44
        "buildContext",
45
        "ViewModelCapabilityDelegate",
46
      );
47

48
  /// Sets the current [BuildContext] for the delegate.
49
  ///
50
  /// This setter is called to update the internal context used by this view
51
  /// capability delegate, typically when the underlying widget is rebuilt or
52
  /// the associated element changes.
53
  ///
54
  /// Implementors should retain the provided [value] for use in subsequent
55
  /// operations that require contextual widget access, theme resolution,
56
  /// localization, or interaction with the widget tree.
57
  ///
58
  /// Throws [MissingCapabilityMethodImplementation] if not overridden.
59
  @mustBeOverridden
4✔
60
  set context(BuildContext value) =>
61
      throw const MissingCapabilityMethodImplementation(
62
        "context",
63
        "ViewModelCapabilityDelegate",
64
      );
65

66
  /// Adds a [UIDriverEvent] to the event stream or processes it within the
67
  /// view capability delegate.
68
  ///
69
  /// [event]: The event originating from the UI driver that should be handled,
70
  /// dispatched, or recorded by the delegate.
71
  ///
72
  /// Implementors should ensure this method properly incorporates the event
73
  /// into the delegate’s event handling pipeline, such as by adding it to a
74
  /// stream, queue, or directly updating application/UI state as necessary.
75
  ///
76
  /// Throws [MissingCapabilityMethodImplementation] if not overridden.
77
  @mustBeOverridden
4✔
78
  void addUIDriverEvent(UIDriverEvent event) =>
79
      throw const MissingCapabilityMethodImplementation(
80
        "addUIDriverEvent",
81
        "ViewModelCapabilityDelegate",
82
      );
83

84
  /// Reports an error that occurred within the UI driver context to the delegate.
85
  ///
86
  /// [error] is the error object or exception that was caught by the driver or related UI logic.
87
  /// [stackTrace] is optional and, if provided, gives debugging context for where the error occurred.
88
  ///
89
  /// Implementors should handle or log the error appropriately, such as reporting to diagnostics,
90
  /// updating UI state, or propagating it to a higher-level error handler.
91
  ///
92
  /// Throws [MissingCapabilityMethodImplementation] if not overridden.
93
  @mustBeOverridden
4✔
94
  void addUIDriverError(Object error, [StackTrace? stackTrace]) =>
95
      throw const MissingCapabilityMethodImplementation(
96
        "addUIDriverError",
97
        "ViewModelCapabilityDelegate",
98
      );
99

100
  /// Notify the driver that the display state of a widget has changed.
101
  ///
102
  /// The [viewTag] parameter specifies which widget's display state has changed.
103
  /// The [state] parameter specifies the new display state of the widget.
104
  ///
105
  /// The possible values for [state] are:
106
  ///
107
  /// * 0: the widget is not visible
108
  /// * 1: the widget is visible and displayed
109
  ///
110
  /// See also:
111
  ///
112
  /// * [DuitDriver], which is the main interface for interacting with the UI
113
  ///   driver.
114
  @mustBeOverridden
4✔
115
  void notifyWidgetDisplayStateChanged(String viewTag, int state) =>
116
      throw const MissingCapabilityMethodImplementation(
117
        "notifyWidgetDisplayStateChanged",
118
        "ViewModelCapabilityDelegate",
119
      );
120

121
  /// Check if a widget is ready to be displayed.
122
  ///
123
  /// The [viewTag] parameter specifies which widget to check.
124
  ///
125
  /// The returned value is true if the widget is ready to be displayed, and false
126
  /// otherwise.
127
  ///
128
  /// See also:
129
  ///
130
  /// * [DuitDriver], which is the main interface for interacting with the UI
131
  ///   driver.
132
  @mustBeOverridden
4✔
133
  bool isWidgetReady(String viewTag) =>
134
      throw const MissingCapabilityMethodImplementation(
135
        "isWidgetReady",
136
        "ViewModelCapabilityDelegate",
137
      );
138

139
  /// Prepares and validates a layout configuration from a JSON-like map, returning a [DuitView] instance.
140
  ///
141
  /// The [json] parameter contains the layout structure, typically representing
142
  /// widgets, properties, and relationships as parsed from a JSON document.
143
  ///
144
  /// Implementations are responsible for parsing the provided structure, constructing
145
  /// the corresponding [DuitView], and returning it for further use, such as rendering.
146
  /// Returning `null` may indicate an invalid or unrecognized layout.
147
  ///
148
  /// Throws [MissingCapabilityMethodImplementation] if not overridden.
149
  ///
150
  /// See also:
151
  ///  - [DuitView], which represents the parsed layout view.
152
  @mustBeOverridden
4✔
153
  Future<DuitView?> prepareLayout(Map<String, dynamic> json) =>
154
      throw const MissingCapabilityMethodImplementation(
155
        "prepareLayout",
156
        "ViewModelCapabilityDelegate",
157
      );
158

159
  /// Called to clean up any external resources, subscriptions, or handlers
160
  /// typically when a delegate is being disposed of or detached. Implementations
161
  /// should ensure all open streams or event sources are closed.
162
  ///
163
  /// This method must be overridden by implementers.
164
  ///
165
  /// Throws [MissingCapabilityMethodImplementation] by default.
166
  @mustBeOverridden
4✔
167
  void releaseResources() => throw const MissingCapabilityMethodImplementation(
168
        "releaseResources",
169
        "ViewModelCapabilityDelegate",
170
      );
171
}
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