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
Improve progress_control documentation and examples
- Update cancel() docs to explain it clears progress and statusMessage
- Add factory variants table for async commands with progress
- Fix Dio integration example to use try-finally pattern
- Remove CommandBuilder example (incompatible with watchValue)
- Remove subjective best practices
- Improve batch processing example to show per-item progress
@@ -137,7 +146,13 @@ if (isCanceled) Text('Operation canceled')
137
146
138
147
### cancel()
139
148
140
-
Request cooperative cancellation of the operation:
149
+
Request cooperative cancellation of the operation. This method:
150
+
151
+
- Sets `isCanceled` to `true`
152
+
- Clears `progress` to `0.0`
153
+
- Clears `statusMessage` to `null`
154
+
155
+
This immediately clears progress state from the UI, providing instant visual feedback that the operation was canceled.
141
156
142
157
```dart
143
158
// In UI:
@@ -185,7 +200,7 @@ if (command.progress.value == 1.0) {
185
200
- Reset progress between manual executions
186
201
- Prepare command state for testing
187
202
188
-
**Note:** Progress is automatically reset at the start of each `run()` execution, so manual resets are typically only needed for UI cleanup or resuming operations.
203
+
**Note:** Progress is automatically reset at the start of each `run()` execution, so manual resets are typically only needed for UI cleanup or resuming operations. Additionally, calling `cancel()` also clears progress and statusMessage to provide immediate visual feedback.
189
204
190
205
## Integration Patterns
191
206
@@ -209,33 +224,6 @@ The `isCanceled` property is a `ValueListenable`, allowing you to forward cancel
Commands created with regular factories (without `WithProgress`) still have progress properties, but they return default values:
@@ -250,13 +238,16 @@ final command = Command.createAsync<void, String>(
250
238
command.progress.value // Always 0.0
251
239
command.statusMessage.value // Always null
252
240
command.isCanceled.value // Always false
253
-
command.cancel() // Does nothing
241
+
command.cancel() // No effect (no progress handle)
254
242
```
255
243
256
244
This zero-overhead design means:
257
-
- <ulstyle="list-style: none; padding-left: 0;"><listyle="padding-left: 1.5em; text-indent: -1.5em;">✅ UI code can always access progress properties without null checks</li></ul>
258
-
- <ulstyle="list-style: none; padding-left: 0;"><listyle="padding-left: 1.5em; text-indent: -1.5em;">✅ No memory cost for commands that don't need progress</li></ul>
259
-
- <ulstyle="list-style: none; padding-left: 0;"><listyle="padding-left: 1.5em; text-indent: -1.5em;">✅ Easy to add progress to existing commands later (just change factory)</li></ul>
245
+
246
+
<ulstyle="list-style: none; padding-left: 0;">
247
+
<listyle="padding-left: 1.5em; text-indent: -1.5em;">✅ UI code can always access progress properties without null checks</li>
248
+
<listyle="padding-left: 1.5em; text-indent: -1.5em;">✅ No memory cost for commands that don't need progress</li>
249
+
<listyle="padding-left: 1.5em; text-indent: -1.5em;">✅ Easy to add progress to existing commands later (just change factory)</li>
250
+
</ul>
260
251
261
252
## Testing with MockCommand
262
253
@@ -296,53 +287,6 @@ for (final item in items) {
296
287
}
297
288
```
298
289
299
-
### DO: Provide meaningful status messages
300
-
301
-
```dart
302
-
// ✅ Good - specific, actionable information
303
-
handle.updateStatusMessage('Uploading file 3 of 10...');
0 commit comments