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
{{ message }}
Repository navigation
Commit 23a35e6
Browse filesBrowse the repository at this point in the historyBrowse files
Improve CommandBuilder documentation clarity and accuracy
- Fix basic example to pass manager via constructor instead of field
- Remove verbose type parameters from all CommandBuilder examples (Dart infers them)
- Add TParam/TResult explanation for builder parameters
- Consolidate builder precedence rules and toWidget() docs in command_builders.md
- Fix emoji formatting to use proper variation selector (❌️)
- Clarify BuildContext availability: passed as parameter in CommandBuilder, accessible from enclosing build in toWidget()
- Add required configuration warnings for lastValue/lastResult patterns
- Update get_it_mixin reference in watch_it docs to clarify it as predecessor
The `lastValue` parameter in `whileRunning` and `onError` will only contain data if the command was created with `includeLastResultInCommandResults: true`. Otherwise, it will always be `null`. See [includeLastResultInCommandResults](/documentation/command_it/command_results#includelastresultincommandresults).
CommandBuilder can automatically execute a command when the widget is first built using the `runCommandOnFirstBuild` parameter. This is particularly useful when not using watch_it (which provides `callOnce` for this purpose).
129
+
130
+
### Basic Usage (No Parameter)
131
+
132
+
```dart
133
+
CommandBuilder(
134
+
command: loadTodosCommand,
135
+
runCommandOnFirstBuild: true, // Executes command in initState
- You only need to show confirmation/success message
233
+
- Result data is irrelevant to the UI
234
+
235
+
**Choose `onData` when:**
236
+
- Command returns data you need to display/use
237
+
- You want to handle non-null data differently from null data
238
+
:::
239
+
240
+
## toWidget() Extension Method
241
+
242
+
The `.toWidget()` extension method on `CommandResult` provides the same declarative builder pattern as `CommandBuilder`, but for use when you already have access to a `CommandResult` (e.g., via `watch_it`, `provider`, or `flutter_hooks`).
| Use case | Direct Command usage | Already watching results |
282
+
| Builder precedence | Same as toWidget() | Same as CommandBuilder |
142
283
143
284
## When to Use What
144
285
145
286
**Use CommandBuilder when:**
146
287
- Building UI directly from a Command
147
-
- Need access to BuildContext in builders
148
288
- Prefer declarative widget composition
149
289
- Don't use state management that exposes results
290
+
- Want BuildContext passed to builder functions
150
291
151
292
**Use toWidget() when:**
152
-
- Already watching `command.results` via get_it_mixin/provider/hooks
153
-
-Don't need BuildContext in builders
154
-
-Want slightly less boilerplate
293
+
- Already watching `command.results` via watch_it/provider/hooks
294
+
-Want simpler builder signatures (no BuildContext parameter)
295
+
-Prefer less boilerplate when already subscribed to results
155
296
156
297
**Use ValueListenableBuilder when:**
157
298
- Need complete control over rendering logic
@@ -164,8 +305,19 @@ class MyWidget extends StatelessWidget with GetItStatefulWidgetMixin {
164
305
165
306
Show stale data while loading fresh data:
166
307
308
+
::: warning Required Configuration
309
+
This pattern requires the command to be created with `includeLastResultInCommandResults: true`. Without this option, `lastItems` will always be `null` during execution. See [Command Results - includeLastResultInCommandResults](/documentation/command_it/command_results#includelastresultincommandresults) for details.
310
+
:::
311
+
167
312
```dart
168
-
CommandBuilder<String, List<Item>>(
313
+
// Command must be created with this option:
314
+
final searchCommand = Command.createAsync<String, List<Item>>(
315
+
searchApi,
316
+
[],
317
+
includeLastResultInCommandResults: true, // Required for pattern below
To display the last successful value (line 7), the command must be created with `includeLastResultInCommandResults: true`. See [Command Results - includeLastResultInCommandResults](/documentation/command_it/command_results#includelastresultincommandresults).
0 commit comments