command_it एक माध्यम है जो `ValueListenable` और `Command` डिज़ाइन पैटर्न के आधार पर अपने राज्य को प्रबंधित करता है। यह flutter_command का एक पुनर्नामीकरण है।
सार्वजनिक जानकारी से बना चयन मार्गदर्शन। केवल संदर्भ हेतु।
command_it एक राज्य प्रबंधन समाधान है जो `ValueListenable` और कमांड डिज़ाइन पैटर्न पर आधारित है, जो Flutter ऐप में राज्य परिवर्तनों के साथ एक साफ, प्रतिक्रियाशील तरीके से निपटने की अनुमति देता है। मूल रूप से flutter_command के नाम से जाना जाता था, यह असिंक्रोनस ऑपरेशन और राज्य अपडेट के प्रबंधन के लिए एक संरचित तरीका प्रदान करता है। पैकेज आदेशों के भीतर क्रियाओं को संगठित करके चिंता के विभाजन को बढ़ावा देता है, जिससे कोड अधिक परीक्षण और रखरखाव योग्य हो जाता है। यह Flutter के प्रतिक्रियाशील फ्रेमवर्क के साथ बिना किसी दिक्कत के एकीकृत होता है और सभी प्रमुख प्लेटफॉर्मों का समर्थन करता है।
उपयोग
एपीआई कॉल जैसे एसिंक ऑपरेशन का प्रबंधन
फॉर्म सबमिशन का प्रबंधन
अनडू/रीडू कार्यक्षमता कार्यान्वित करना
कई विजेट्स के मध्य राज्य परिवर्तनों को समन्वयित करना
पुन: उपयोगी व्यवसाय तर्क परत निर्माण
मुख्य विशेषताएँ
ValueListenable के माध्यम से प्रतिक्रियाशील अवस्था
आदेश पैटर्न एकीकृत क्रियाओं के लिए है
लोडिंग, त्रुटि और सफलता स्थितियों के लिए बिल्ट-इन समर्थन
Flutter के widget वृक्ष के साथ आसान एकीकरण
क्रॉस-प्लेटफॉर्म संगतता
इनके लिए उपयुक्त
हल्के राज्य प्रबंधन विकल्प की तलाश में विकासकर्ता
UI और व्यावसायिक तर्क के बीच स्पष्ट अलगाव चाहने वाली टीमें
पूर्वानुमानित अवस्था परिवर्तन की आवश्यकता वाले प्रोजेक्ट
अक्सर एसिंक ऑपरेशन करने वाले ऐप्स
टेस्ट-ड्रिवन डेवलपमेंट वर्कफ्लो
विचार योग्य बातें
नए उपयोगकर्ताओं के लिए जो कमांड पैटर्न से परिचित नहीं हैं, इसके लिए सीखने का वक्र आवश्यक हो सकता है
बहुत सरल राज्य की आवश्यकताओं के लिए कम उपयुक्त
बड़े राज्य प्रबंधन समाधानों की तुलना में सीमित पारिस्थितिकी तंत्र
पूर्ण एप्लिकेशन संरचना के लिए अन्य उपकरणों के साथ सबसे अच्छी तरह से जुड़ता है
मूल README
संबंधित सोर्स रिपॉज़िटरी के मूल README का स्नैपशॉट। नवीनतम सामग्री के लिए रिपॉज़िटरी देखें।
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.
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
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.
Ecosystem Integration
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 managersclassTodoManager{
final loadTodosCommand = Command.createAsyncNoParam<List<Todo>>(
() => api.fetchTodos(),
[],
);
// Debounce search with listen_it operatorsfinal 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: