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

Duit-Foundation / flutter_duit / 19115039532

05 Nov 2025 08:15PM UTC coverage: 86.358% (+8.9%) from 77.409%
19115039532

push

github

web-flow
major: flutter_duit v4 (#310)

2151 of 2405 new or added lines in 109 files covered. (89.44%)

36 existing lines in 7 files now uncovered.

3773 of 4369 relevant lines covered (86.36%)

35.87 hits per line

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

90.0
/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({
324✔
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
244✔
74
  void updateState(Map<String, dynamic> newState) {
75
    attributes.payload.addAll(newState);
732✔
76
    notifyListeners();
244✔
77
  }
78

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

108
  FutureOr<void> _performAsync(ServerAction action) async {
8✔
109
    final opts = action.executionOptions;
8✔
110
    if (opts != null) {
111
      switch (opts.modifier) {
4✔
112
        case ExecutionModifier.throttle:
4✔
113
          throttleWithArgs(
4✔
114
            action.eventName,
4✔
115
            (arg) async => await driver.execute(arg),
12✔
116
            action,
117
            duration: opts.duration,
4✔
118
          );
119
          break;
120
        case ExecutionModifier.debounce:
4✔
121
          debounceWithArgs(
4✔
122
            action.eventName,
4✔
123
            (arg) async => await driver.execute(arg),
12✔
124
            action,
125
            duration: opts.duration,
4✔
126
          );
127
          break;
128
        default:
NEW
129
          await driver.execute(action);
×
130
          break;
131
      }
132
    } else {
133
      await driver.execute(action);
16✔
134
    }
135
  }
136

137
  /// Performs the related action of the UI element.
138
  ///
139
  /// This method is called when the UI element is interacted with and the associated
140
  /// server action is not null. It executes the server action using the driver.
141
  @override
36✔
142
  void performRelatedAction() {
143
    try {
144
      if (action != null) {
36✔
145
        _perform(action!);
32✔
146
      }
147
    } catch (e, s) {
148
      driver.logger?.error(
×
149
        "Error while perform performRelatedAction method",
150
        error: e,
151
        stackTrace: s,
152
      );
153
    }
154
  }
155

156
  @override
8✔
157
  Future<void> performRelatedActionAsync() async {
158
    try {
159
      if (action != null) {
8✔
160
        await _performAsync(action!);
16✔
161
      }
162
    } catch (e, s) {
163
      driver.logger?.error(
×
164
        "Error while perform performRelatedActionAsync method",
165
        error: e,
166
        stackTrace: s,
167
      );
168
    }
169
  }
170

171
  @override
36✔
172
  void performAction(ServerAction? action) {
173
    try {
174
      if (action != null) {
175
        _perform(action);
32✔
176
      }
177
    } catch (e, s) {
178
      driver.logger?.error(
×
179
        "Error while performing performAction method",
180
        error: e,
181
        stackTrace: s,
182
      );
183
    }
184
  }
185

186
  @override
4✔
187
  Future<void> performActionAsync(ServerAction? action) async {
188
    try {
189
      if (action != null) {
190
        await _performAsync(action);
4✔
191
      }
192
    } catch (e, s) {
193
      driver.logger?.error(
×
194
        "Error while performing performActionAsync method",
195
        error: e,
196
        stackTrace: s,
197
      );
198
    }
199
  }
200

201
  @override
320✔
202
  void detach() {
203
    driver.detachController(id);
960✔
204
    cancelAll();
320✔
205
  }
206

207
  @override
208
  late final StreamController<RemoteCommand> commandChannel;
209

210
  @override
8✔
211
  FutureOr<void> emitCommand(RemoteCommand command) async {
212
    try {
213
      final specifiedCommand = SpecCommand(command).specify();
16✔
214
      commandChannel.add(specifiedCommand);
8✔
215
    } catch (e, s) {
216
      driver.logger
8✔
217
          ?.error("Error while emitting command", error: e, stackTrace: s);
4✔
218
    }
219
  }
220

221
  @override
12✔
222
  void removeCommandListener() => commandChannel.close();
24✔
223

224
  @override
320✔
225
  void listenCommand(CommandListener callback) {
226
    commandChannel = StreamController<RemoteCommand>()..stream.listen(callback);
1,280✔
227
  }
228
}
229

230
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