Skip to content

Commit e1a3487

Browse files
committed
Update command_it skill: isRunningSync usage, error reset behavior, global error stream
1 parent 9aede73 commit e1a3487

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

skills/command_it-expert.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ final result = await command.runAsync(param); // Await result (async commands o
5757
## Observable Properties (all ValueListenable)
5858

5959
```dart
60-
command.isRunning // ValueListenable<bool> - ASYNC ONLY (asserts on sync)
61-
command.isRunningSync // ValueListenable<bool> - safe for restrictions
60+
command.isRunning // ValueListenable<bool> - ASYNC ONLY (asserts on sync), use for UI
61+
command.isRunningSync // ValueListenable<bool> - ONLY for restrictions, NOT for UI updates
6262
command.canRun // ValueListenable<bool> - !restriction && !isRunning
6363
command.errors // ValueListenable<CommandError<TParam>?>
6464
command.errorsDynamic // ValueListenable<CommandError<dynamic>?>
@@ -172,8 +172,19 @@ Command.globalExceptionHandler = (CommandError error, StackTrace stackTrace) {
172172
};
173173
```
174174

175+
**Global error stream** - `Command.globalErrors` is a `Stream<CommandError>` of all globally-handled errors. Use `registerStreamHandler` in your root widget to show toasts for errors not handled locally:
176+
```dart
177+
// In root widget (e.g. MyApp)
178+
registerStreamHandler(
179+
target: Command.globalErrors,
180+
handler: (context, snapshot, cancel) {
181+
if (snapshot.hasData) showErrorToast(context, snapshot.data!.error);
182+
},
183+
);
184+
```
185+
175186
**Listening to errors**:
176-
`.errors` only emits actual `CommandError` objects - no null check needed. It only emits null if you explicitly call `clearErrors()`.
187+
`.errors` only emits actual `CommandError` objects - no null check needed. Errors are automatically reset to null on each new `run()` without triggering handlers.
177188
```dart
178189
// With listen_it
179190
command.errors.listen((error, subscription) {

0 commit comments

Comments
 (0)