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

Duit-Foundation / duit_kernel / 20682343798

03 Jan 2026 08:12PM UTC coverage: 76.339% (-0.3%) from 76.636%
20682343798

Pull #51

github

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

0 of 9 new or added lines in 1 file covered. (0.0%)

2 existing lines in 2 files now uncovered.

1768 of 2316 relevant lines covered (76.34%)

4.85 hits per line

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

0.0
/lib/src/capabilities/view_capability.dart
1
import "package:duit_kernel/duit_kernel.dart";
2
import "package:flutter/widgets.dart";
3
import "package:meta/meta.dart";
4

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

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

33
  /// The build context associated with the UI driver.
NEW
34
  @mustBeOverridden
×
35
  BuildContext get buildContext =>
36
      throw const MissingCapabilityMethodImplementation(
37
        "buildContext",
38
        "ViewModelCapabilityDelegate",
39
      );
40

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

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

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

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

114
  /// Check if a widget is ready to be displayed.
115
  ///
116
  /// The [viewTag] parameter specifies which widget to check.
117
  ///
118
  /// The returned value is true if the widget is ready to be displayed, and false
119
  /// otherwise.
120
  ///
121
  /// See also:
122
  ///
123
  /// * [DuitDriver], which is the main interface for interacting with the UI
124
  ///   driver.
NEW
125
  @mustBeOverridden
×
126
  bool isWidgetReady(String viewTag) =>
127
      throw const MissingCapabilityMethodImplementation(
128
        "isWidgetReady",
129
        "ViewModelCapabilityDelegate",
130
      );
131

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

152
  /// Called to clean up any external resources, subscriptions, or handlers
153
  /// typically when a delegate is being disposed of or detached. Implementations
154
  /// should ensure all open streams or event sources are closed.
155
  ///
156
  /// This method must be overridden by implementers.
157
  ///
158
  /// Throws [MissingCapabilityMethodImplementation] by default.
NEW
159
  @mustBeOverridden
×
160
  void releaseResources() => throw const MissingCapabilityMethodImplementation(
161
        "releaseResources",
162
        "ViewModelCapabilityDelegate",
163
      );
164
}
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