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

Duit-Foundation / flutter_duit / 21026233449

15 Jan 2026 09:26AM UTC coverage: 80.184% (-8.3%) from 88.441%
21026233449

push

github

web-flow
feat: Capability-based API migration pt2 (#323)

162 of 408 new or added lines in 23 files covered. (39.71%)

328 existing lines in 17 files now uncovered.

4354 of 5430 relevant lines covered (80.18%)

34.33 hits per line

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

41.51
/lib/src/controller/view_controller.dart
1
import "dart:async";
2

3
import "package:duit_kernel/duit_kernel.dart";
4
import "package:flutter/foundation.dart";
5
import "package:flutter_duit/src/utils/invoker.dart";
6
import "package:flutter_duit/src/controller/index.dart";
7

8
/// The controller for a UI element.
9
///
10
/// This class is responsible for managing the state and behavior of a UI element.
11
/// It implements the [UIElementController] interface and uses the [ChangeNotifier]
12
/// mixin to provide change notification to listeners.
13
final class ViewController<T>
14
    with ChangeNotifier, ActionInvoker
15
    implements UIElementController {
16
  /// The attributes associated with the UI element.
17
  ///
18
  /// This property holds the attributes of the UI element that the `ViewController` controls.
19
  /// It can be used to access and modify the attributes of the UI element.
20
  @override
21
  ViewAttribute attributes;
22

23
  /// The server action associated with the UI element.
24
  ///
25
  /// This property holds the server action that is triggered when the UI element is interacted with.
26
  @override
27
  ServerAction? action;
28

29
  /// The driver that controls the UI element.
30
  ///
31
  /// This property holds the driver object that is responsible for interacting with the UI element.
32
  @override
33
  UIDriver driver;
34

35
  /// The unique identifier of the UI element.
36
  ///
37
  /// This property holds the unique identifier that is assigned to the UI element.
38
  @override
39
  String id;
40

41
  /// The type of the UI element.
42
  ///
43
  /// This property holds the type of the UI element that the `ViewController` controls.
44
  @override
45
  String type;
46

47
  /// The tag associated with the UI element.
48
  ///
49
  /// This property holds an optional tag that can be used to further categorize the UI element.
50
  @override
51
  String? tag;
52

53
  /// Creates a new instance of the `ViewController` class.
54
  ///
55
  /// The [id] parameter specifies the unique identifier of the UI element.
56
  /// The [driver] parameter specifies the driver that controls the UI element.
57
  /// The [type] parameter specifies the type of the UI element.
58
  /// The [action] parameter specifies the server action associated with the UI element.
59
  /// The [attributes] parameter specifies the initial attributes of the UI element.
60
  /// The [tag] parameter specifies the tag associated with the UI element.
61
  ViewController({
344✔
62
    required this.id,
63
    required this.driver,
64
    required this.type,
65
    required this.attributes,
66
    this.action,
67
    this.tag,
68
  });
69

70
  /// Updates the state of the UI element with new attributes.
71
  ///
72
  /// The [newAttrs] parameter specifies the new attributes to be applied to the UI element.
73
  @override
248✔
74
  void updateState(Map<String, dynamic> newState) {
75
    attributes.payload.addAll(newState);
744✔
76
    notifyListeners();
248✔
77
  }
78

79
  void _perform(ServerAction action) {
32✔
80
    final opts = action.executionOptions;
32✔
81
    if (opts != null) {
UNCOV
82
      switch (opts.modifier) {
×
UNCOV
83
        case ExecutionModifier.throttle:
×
UNCOV
84
          throttleWithArgs(
×
UNCOV
85
            action.eventName,
×
UNCOV
86
            driver.execute,
×
87
            action,
UNCOV
88
            duration: opts.duration,
×
89
          );
90
          break;
UNCOV
91
        case ExecutionModifier.debounce:
×
UNCOV
92
          debounceWithArgs(
×
UNCOV
93
            action.eventName,
×
UNCOV
94
            driver.execute,
×
95
            action,
UNCOV
96
            duration: opts.duration,
×
97
          );
98
          break;
99
      }
100
    } else {
101
      driver.execute(action);
64✔
102
    }
103
  }
104

UNCOV
105
  FutureOr<void> _performAsync(ServerAction action) async {
×
UNCOV
106
    final opts = action.executionOptions;
×
107
    if (opts != null) {
UNCOV
108
      switch (opts.modifier) {
×
UNCOV
109
        case ExecutionModifier.throttle:
×
UNCOV
110
          throttleWithArgs(
×
UNCOV
111
            action.eventName,
×
UNCOV
112
            driver.execute,
×
113
            action,
UNCOV
114
            duration: opts.duration,
×
115
          );
116
          break;
UNCOV
117
        case ExecutionModifier.debounce:
×
UNCOV
118
          debounceWithArgs(
×
UNCOV
119
            action.eventName,
×
UNCOV
120
            driver.execute,
×
121
            action,
UNCOV
122
            duration: opts.duration,
×
123
          );
124
          break;
125
      }
126
    } else {
UNCOV
127
      await driver.execute(action);
×
128
    }
129
  }
130

131
  /// Performs the related action of the UI element.
132
  ///
133
  /// This method is called when the UI element is interacted with and the associated
134
  /// server action is not null. It executes the server action using the driver.
135
  @override
36✔
136
  void performRelatedAction() {
137
    if (action != null) {
36✔
138
      _perform(action!);
24✔
139
    }
140
  }
141

UNCOV
142
  @override
×
143
  Future<void> performRelatedActionAsync() async {
UNCOV
144
    if (action != null) {
×
UNCOV
145
      await _performAsync(action!);
×
146
    }
147
  }
148

149
  @override
32✔
150
  void performAction(ServerAction? action) {
151
    if (action != null) {
152
      _perform(action);
28✔
153
    }
154
  }
155

UNCOV
156
  @override
×
157
  Future<void> performActionAsync(ServerAction? action) async {
158
    if (action != null) {
UNCOV
159
      await _performAsync(action);
×
160
    }
161
  }
162

163
  @override
336✔
164
  void detach() {
165
    driver.detachController(id);
1,008✔
166
    cancelAll();
336✔
167
  }
168

169
  @override
170
  late final StreamController<RemoteCommand> commandChannel;
171

172
  @override
16✔
173
  FutureOr<void> emitCommand(RemoteCommand command) async {
174
    try {
175
      final specifiedCommand = SpecCommand(command).specify();
32✔
176
      commandChannel.add(specifiedCommand);
32✔
177
    } catch (e, s) {
NEW
178
      driver.logError(
×
179
        "Error while emitting command",
180
        e,
181
        s,
182
      );
183
    }
184
  }
185

186
  @override
12✔
187
  void removeCommandListener() => commandChannel.close();
24✔
188

189
  @override
336✔
190
  void listenCommand(CommandListener callback) {
191
    commandChannel = StreamController<RemoteCommand>()..stream.listen(callback);
1,344✔
192
  }
193
}
194

195
typedef CommandListener = Future<void> Function(RemoteCommand command);
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