command_it
command_it एक माध्यम है जो `ValueListenable` और `Command` डिज़ाइन पैटर्न के आधार पर अपने राज्य को प्रबंधित करता है। यह flutter_command का एक पुनर्नामीकरण है।
flutter_command की पुनर्ब्रांडेड फॉर्क, भविष्य में विकास यहाँ होगा
{"sdk":"flutter"}^6.0.0^1.11.0^3.0.0^1.3.1—{"sdk":"flutter"}^2.0.1यह अंग्रेज़ी मूल स्नैपशॉट है। नवीनतम सामग्री GitHub पर देखें।
📚 Complete documentation available at flutter-it.dev Check out the comprehensive docs with detailed guides, examples, and best practices!
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→canRunRun
dart fix --applyto automatically update most usages.
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 — A construction set of independent packages. command_it works standalone or combines with watch_it for reactive UI updates.
Learn more about the benefits →
Add to your pubspec.yaml:
dependencies:
command_it: ^9.0.2
listen_it: ^5.3.3 # Required - commands build on ValueListenable
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<String>(
() 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<bool>(
valueListenable: manager.incrementCommand.isRunning,
builder: (context, isRunning, _) {
if (isRunning) return CircularProgressIndicator();
return ValueListenableBuilder<String>(
valueListenable: manager.incrementCommand,
builder: (context, value, _) => Text('Count: $value'),
);
},
),
ElevatedButton(
onPressed: manager.incrementCommand.run,
child: Text('Increment'),
),
],
);
}
}
That's it! The command automatically:
Simplify your UI code with the built-in builder widget:
CommandBuilder<void, String>(
command: manager.incrementCommand,
whileRunning: (context, _, __) => CircularProgressIndicator(),
onData: (context, value, _) => Text('Count: $value'),
onError: (context, error, _, __) => Text('Error: $error'),
)
Create commands for any function signature:
Observe different aspects of execution:
Declarative error routing with filters:
Chain commands together with the pipeToCommand() extension. When the source completes successfully, it automatically triggers the target command:
// 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.
Built on listen_it — Commands are ValueListenable objects, so they work with all listen_it operators (map, debounce, where, etc.).
// Register with get_it
di.registerLazySingleton(() => TodoManager());
// Use commands in your managers
class TodoManager {
final loadTodosCommand = Command.createAsyncNoParam<List<Todo>>(
() => api.fetchTodos(),
[],
);
// Debounce search with listen_it operators
final searchCommand = Command.createSync<String, String>((s) => s, '');
TodoManager() {
searchCommand.debounce(Duration(milliseconds: 500)).listen((term, _) {
loadTodosCommand.run();
});
}
}
Want more? Combine with other flutter_it packages:
listen_it — Required dependency. ValueListenable operators and reactive collections.
Optional: watch_it — State management. Watch commands reactively without builders: watchValue((m) => m.loadCommand).
Optional: get_it — Service locator for dependency injection. Access managers with commands from anywhere: di<TodoManager>().
💡 flutter_it is a construction set — command_it works standalone. Add watch_it and get_it when you need reactive UI and dependency injection.
This package ships an Agent Skill for AI coding assistants
(Claude Code, Cursor, GitHub Copilot, Codex, Gemini CLI and others) in skills/command-it-expert/.
It teaches them the critical rules, common patterns and anti-patterns of command_it.
Install it into your project with the official Dart skills tool:
dart run skills@ get
For the ecosystem-wide skills (architecture guidance, feed/data-source patterns, overview) and the skills of the other flutter_it packages run:
dart run skills@ add flutter-it/flutter_it
Contributions are welcome! Please read the contributing guidelines before submitting PRs.
MIT License - see LICENSE file for details.
Part of the flutter_it ecosystem — Build reactive Flutter apps the easy way. No codegen, no boilerplate, just code.