# command_it
**Repository Path**: yeild_libs/command_it
## Basic Information
- **Project Name**: command_it
- **Description**: No description available
- **Primary Language**: Dart
- **License**: Not specified
- **Default Branch**: main
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2025-08-02
- **Last Updated**: 2026-04-21
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# command_it
> ๐ **[Complete documentation available at flutter-it.dev](https://flutter-it.dev/documentation/command_it/getting_started)**
> Check out the comprehensive docs with detailed guides, examples, and best practices!
---
## ๐ Migration Notice (v9.0.0)
> **Important:** Version 9.0.0 introduces new, clearer API naming. The old API is deprecated and will be removed in v10.0.0.
>
> **Quick Migration:** `execute()` โ `run()` | `isExecuting` โ `isRunning` | `canExecute` โ `canRun`
>
> Run `dart fix --apply` to automatically update most usages.
>
> [Complete migration guide โ](BREAKING_CHANGE_EXECUTE_TO_RUN.md)
---
**Command pattern for Flutter - wrap functions as observable objects with automatic state management**
Commands replace async methods with reactive alternatives. Wrap your functions, get automatic loading states, error handling, and UI integration. No manual state tracking, no try/catch everywhere.
Call them like functions. React to their state. Simple as that.
> **Part of [flutter_it](https://flutter-it.dev)** โ A construction set of independent packages. command_it works standalone or combines with watch_it for reactive UI updates.
## Why Commands?
- **๐ฏ Declarative** โ Wrap functions, get observable execution state automatically
- **โก Automatic State** โ isRunning, value, errors tracked without manual code
- **๐ก๏ธ Smart Error Handling** โ Route errors globally/locally with filters
- **๐ Built-in Protection** โ Prevents parallel execution automatically
- **๐๏ธ Restrictions** โ Disable commands conditionally (auth, network, etc.)
- **๐งช Testable** โ Easier to test than traditional async methods
[Learn more about the benefits โ](https://flutter-it.dev/documentation/command_it/getting_started)
## Quick Start
### Installation
Add to your `pubspec.yaml`:
```yaml
dependencies:
command_it: ^9.0.2
listen_it: ^5.3.3 # Required - commands build on ValueListenable
```
### Basic Example
```dart
import 'package:command_it/command_it.dart';
// 1. Create a command that wraps your async function
class CounterManager {
int _counter = 0;
late final incrementCommand = Command.createAsyncNoParam(
() async {
await Future.delayed(Duration(milliseconds: 500));
_counter++;
return _counter.toString();
},
initialValue: '0',
);
}
// 2. Use it in your UI - command is a ValueListenable
class CounterWidget extends StatelessWidget {
final manager = CounterManager();
@override
Widget build(BuildContext context) {
return Column(
children: [
// Shows loading indicator automatically while command runs
ValueListenableBuilder(
valueListenable: manager.incrementCommand.isRunning,
builder: (context, isRunning, _) {
if (isRunning) return CircularProgressIndicator();
return ValueListenableBuilder(
valueListenable: manager.incrementCommand,
builder: (context, value, _) => Text('Count: $value'),
);
},
),
ElevatedButton(
onPressed: manager.incrementCommand.run,
child: Text('Increment'),
),
],
);
}
}
```
**That's it!** The command automatically:
- Prevents parallel execution
- Tracks isRunning state
- Publishes results
- Handles errors
[Full tutorial](https://flutter-it.dev/documentation/command_it/getting_started)
### Using CommandBuilder
Simplify your UI code with the built-in builder widget:
```dart
CommandBuilder(
command: manager.incrementCommand,
whileRunning: (context, _, __) => CircularProgressIndicator(),
onData: (context, value, _) => Text('Count: $value'),
onError: (context, error, _, __) => Text('Error: $error'),
)
```
## Key Features
### Command Types
Create commands for any function signature:
- **[createAsync](https://flutter-it.dev/documentation/command_it/command_types#createasync)** โ Async with parameter and result
- **[createAsyncNoParam](https://flutter-it.dev/documentation/command_it/command_types#createasyncnoparam)** โ Async without parameter
- **[createAsyncNoResult](https://flutter-it.dev/documentation/command_it/command_types#createasyncnoresult)** โ Async that returns nothing
- **[createSync](https://flutter-it.dev/documentation/command_it/command_types#createsync)** โ Sync with parameter and result
- Plus NoParam and NoResult variants for sync commands
### Command Properties
Observe different aspects of execution:
- **[value](https://flutter-it.dev/documentation/command_it/command_properties#value)** โ Last successful result
- **[isRunning](https://flutter-it.dev/documentation/command_it/command_properties#isrunning)** โ Async execution state
- **[isRunningSync](https://flutter-it.dev/documentation/command_it/command_properties#isrunningsync)** โ Synchronous version for restrictions
- **[canRun](https://flutter-it.dev/documentation/command_it/command_properties#canrun)** โ Combined restriction and running state
- **[errors](https://flutter-it.dev/documentation/command_it/command_properties#errors)** โ Stream of errors
- **[results](https://flutter-it.dev/documentation/command_it/command_results)** โ CommandResult with all data at once
### Error Handling
Declarative error routing with filters:
- **[Basic Error Handling](https://flutter-it.dev/documentation/command_it/error_handling)** โ Listen to errors locally
- **[Global Handler](https://flutter-it.dev/documentation/command_it/error_handling#global-handler)** โ App-wide error handling
- **[Global Errors Stream](https://flutter-it.dev/documentation/command_it/global_configuration#globalerrors)** โ Reactive monitoring of all globally-routed errors
- **[Error Filters](https://flutter-it.dev/documentation/command_it/error_filters)** โ Route errors by type or predicate
- **[Built-in Filters](https://flutter-it.dev/documentation/command_it/error_filters#built-in-filters)** โ GlobalIfNoLocalErrorFilter, PredicatesErrorFilter, etc.
### Advanced Features
- **[Command Restrictions](https://flutter-it.dev/documentation/command_it/restrictions)** โ Disable commands conditionally
- **[CommandBuilder](https://flutter-it.dev/documentation/command_it/command_builders)** โ Widget for simpler UI code
- **[Undoable Commands](https://flutter-it.dev/documentation/command_it/undoable_commands)** โ Built-in undo/redo support
- **[Command Piping](#piping-commands)** โ Chain commands together automatically
- **[Testing](https://flutter-it.dev/documentation/command_it/testing)** โ Patterns for testing commands
### Piping Commands
Chain commands together with the `pipeToCommand()` extension. When the source completes successfully, it automatically triggers the target command:
```dart
// Trigger refresh after save completes
saveCommand.pipeToCommand(refreshCommand);
// Transform result before passing to target
userIdCommand.pipeToCommand(fetchUserCommand, transform: (id) => UserRequest(id));
// Pipe from any ValueListenable - track execution state changes
longRunningCommand.isRunning.pipeToCommand(spinnerStateCommand);
```
The `pipeToCommand()` extension works on any `ValueListenable`, including commands, `isRunning`, `results`, or plain `ValueNotifier`. Returns a `ListenableSubscription` for manual cancellation if needed.
> โ ๏ธ **Warning:** Circular pipes (AโBโA) cause infinite loops. Ensure your pipe graph is acyclic.
## Ecosystem Integration
**Built on listen_it** โ Commands are `ValueListenable` objects, so they work with all listen_it operators (map, debounce, where, etc.).
```dart
// Register with get_it
di.registerLazySingleton(() => TodoManager());
// Use commands in your managers
class TodoManager {
final loadTodosCommand = Command.createAsyncNoParam>(
() => api.fetchTodos(),
[],
);
// Debounce search with listen_it operators
final searchCommand = Command.createSync((s) => s, '');
TodoManager() {
searchCommand.debounce(Duration(milliseconds: 500)).listen((term, _) {
loadTodosCommand.run();
});
}
}
```
**Want more?** Combine with other flutter_it packages:
- **[listen_it](https://pub.dev/packages/listen_it)** โ **Required dependency.** ValueListenable operators and reactive collections.
- **Optional: [watch_it](https://pub.dev/packages/watch_it)** โ State management. Watch commands reactively without builders: `watchValue((m) => m.loadCommand)`.
- **Optional: [get_it](https://pub.dev/packages/get_it)** โ Service locator for dependency injection. Access managers with commands from anywhere: `di()`.
> ๐ก **flutter_it is a construction set** โ command_it works standalone. Add watch_it and get_it when you need reactive UI and dependency injection.
[Explore the ecosystem โ](https://flutter-it.dev)
## AI-Assisted Development
This package includes **AI skill files** in the `skills/` directory that help AI coding assistants
(Claude Code, Cursor, GitHub Copilot, and others) generate correct code using command_it.
The skill files teach AI tools critical rules, common patterns, and anti-patterns specific to command_it.
Included skills: `command-it-expert`, `listen-it-expert`, `flutter-architecture-expert`, `feed-datasource-expert`.
They follow the [Agent Skills](https://github.com/agentskills) open standard.
[Learn more about AI skills โ](https://flutter-it.dev/misc/ai_skills)
## Learn More
### ๐ Documentation
- **[Getting Started Guide](https://flutter-it.dev/documentation/command_it/getting_started)** โ Installation, concepts, first command
- **[Command Basics](https://flutter-it.dev/documentation/command_it/command_basics)** โ Creating and running commands
- **[Command Properties](https://flutter-it.dev/documentation/command_it/command_properties)** โ value, isRunning, canRun, errors, results
- **[Command Types](https://flutter-it.dev/documentation/command_it/command_types)** โ Choosing the right factory function
- **[Error Handling](https://flutter-it.dev/documentation/command_it/error_handling)** โ Basic error patterns
- **[Error Filters](https://flutter-it.dev/documentation/command_it/error_filters)** โ Advanced error routing
- **[Command Restrictions](https://flutter-it.dev/documentation/command_it/restrictions)** โ Conditional execution control
- **[Command Builders](https://flutter-it.dev/documentation/command_it/command_builders)** โ Simplifying UI code
- **[Testing Commands](https://flutter-it.dev/documentation/command_it/testing)** โ Test patterns and examples
- **[Integration with watch_it](https://flutter-it.dev/documentation/command_it/watch_it_integration)** โ Reactive UI updates
- **[Best Practices](https://flutter-it.dev/documentation/command_it/best_practices)** โ Patterns, anti-patterns, tips
### ๐ฌ Community & Support
- **[Discord](https://discord.gg/ZHYHYCM38h)** โ Get help, share ideas, connect with other developers
- **[GitHub Issues](https://github.com/escamoteur/command_it/issues)** โ Report bugs, request features
- **[GitHub Discussions](https://github.com/escamoteur/command_it/discussions)** โ Ask questions, share patterns
## Contributing
Contributions are welcome! Please read the [contributing guidelines](CONTRIBUTING.md) before submitting PRs.
## License
MIT License - see [LICENSE](LICENSE) file for details.
---
**Part of the [flutter_it ecosystem](https://flutter-it.dev)** โ Build reactive Flutter apps the easy way. No codegen, no boilerplate, just code.