You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Create new global_configuration.md with all static Command properties
- Remove Global Configuration section from command_properties.md
- Update navigation to include Global Configuration after Command Results
- Add Global Configuration link to See Also section
- Update command_properties.md with improved error handling examples
- Add error handling section to without_watch_it.md
- Update CommandResult structure in command_results.md
**Accessing `.isRunning` on sync commands throws an assertion error.** Sync commands execute immediately without giving the UI time to react, so tracking execution state isn't meaningful.
- Single `ValueListenableBuilder` instead of multiple nested builders
248
+
- Need comprehensive state (running, data, error) in one place
249
+
- Want parameter data for error messages or retry logic
250
+
251
+
**See [Command Results](/documentation/command_it/command_results) for complete CommandResult structure, examples, and the `includeLastResultInCommandResults` parameter.**
256
252
257
253
## errorsDynamic - Dynamic Error Type
258
254
@@ -271,13 +267,13 @@ ValueListenable<CommandError<dynamic>?> get errorsDynamic => _errors;
271
267
final saveCommand = Command.createAsync<Data, void>(...);
272
268
final deleteCommand = Command.createAsync<String, void>(...);
::: tip Using listen/registerHandler - No Clear Needed
317
+
If you use `.listen()` or `registerHandler()` to watch errors, they only get called when a new error appears (not when cleared to null). In this case, you typically don't need `clearErrors()` at all:
318
+
319
+
**With `.listen()`:**
320
+
```dart
321
+
command.errors.listen((error, _) {
322
+
showSnackBar(error!.error.toString()); // Shows once per error, never null
323
+
});
324
+
```
325
+
326
+
**With `registerHandler()` (watch_it):**
327
+
```dart
328
+
registerHandler((Manager m) => m.command.errors, (context, error, cancel) {
329
+
showSnackBar(error!.error.toString()); // Shows once per error, never null
330
+
});
331
+
```
332
+
333
+
Since listeners only fire on actual errors (never null), each error is shown once and you don't need to manually clear.
334
+
335
+
**Important:** If you DO call `clearErrors()` elsewhere in your code, handlers will receive `null` when the error is cleared. In that case, add a null check:
300
336
301
337
```dart
302
-
// Error handling with manual dismissal
303
338
command.errors.listen((error, _) {
304
339
if (error != null) {
305
-
showErrorDialog(
306
-
error.error.toString(),
307
-
onDismiss: () => command.clearErrors(),
308
-
);
340
+
showSnackBar(error.error.toString());
309
341
}
310
342
});
311
343
```
312
344
345
+
**Use `clearErrors()` when:**
346
+
- Watching errors with `watchValue` - rebuilds on every change, needs manual clear to hide UI
347
+
- Conditionally showing error widgets based on error state
348
+
:::
349
+
313
350
::: tip Clearing Errors Without Notification
314
351
You can also set `command.errors.value = null` directly to clear the error WITHOUT triggering listeners. This is useful if you want to silently reset the error state.
315
352
@@ -318,8 +355,6 @@ You can also set `command.errors.value = null` directly to clear the error WITHO
318
355
Use `clearErrors()` when you want UI updates (e.g., dismissing error messages). Use direct assignment when you don't.
319
356
:::
320
357
321
-
**Note:** Preferred error handling is via `registerHandler` or `listen` in `initState` of a `StatefulWidget`, but `clearErrors()` is especially useful with watch_it.
322
-
323
358
## name - Debug Identifier
324
359
325
360
Returns the debug name set via `debugName` parameter:
0 commit comments