### Complete Flutter Application Example with flutter_it Source: https://context7.com/flutter-it/flutter_it/llms.txt Demonstrates a full Flutter application integrating flutter_it for dependency injection, state management, and asynchronous command execution. It includes service setup, command creation for fetching user data, and a reactive widget to display user information. ```dart import 'package:flutter_it/flutter_it.dart'; import 'package:flutter/material.dart'; // Services class UserService extends ChangeNotifier { User? _currentUser; User? get currentUser => _currentUser; void setUser(User user) { _currentUser = user; notifyListeners(); } } // Setup dependency injection final getIt = GetIt.instance; void setupDependencies() { getIt.registerSingleton(UserService()); } // Create commands for async operations final fetchUserCommand = Command.createAsync( (userId) async { final response = await http.get('/api/users/$userId'); return User.fromJson(response.data); }, initialValue: null, ); // Reactive widget using all packages class UserProfileWidget extends WatchingWidget { @override Widget build(BuildContext context) { final userService = watchIt(); final user = watchValue((UserService s) => s.currentUser); final isLoading = watchValue((Command c) => c.isRunning, target: fetchUserCommand); if (isLoading) { return const CircularProgressIndicator(); } if (user == null) { return ElevatedButton( onPressed: () => fetchUserCommand.run('user-123'), child: const Text('Load User'), ); } return Text('Welcome, ${user.name}!'); } } void main() { setupDependencies(); runApp(const MyApp()); } ``` -------------------------------- ### Flutter_it Ecosystem Usage Example (Dart) Source: https://github.com/flutter-it/flutter_it/blob/main/README.md A comprehensive example showcasing the integration of get_it for dependency injection, watch_it for reactive UI, command_it for asynchronous operations with loading states, and listen_it for ValueListenable operators within a Flutter application. ```dart import 'package:flutter_it/flutter_it.dart'; // Use get_it for dependency injection final getIt = GetIt.instance; void setup() { getIt.registerSingleton(ApiService()); } // Use watch_it for reactive UI class MyWidget extends WatchingWidget { @override Widget build(BuildContext context) { final api = watchIt(); final data = watchValue((DataModel m) => m.value); return Text('$data'); } } // Use command_it for async operations with loading states final loginCommand = Command.createAsync( (credentials) async => apiLogin(credentials), initialValue: false, ); // Use listen_it for ValueListenable operators final filteredItems = itemsNotifier .where((items) => items.length > 0) .map((items) => items.take(10)); ``` -------------------------------- ### Dependency Registration with get_it Source: https://context7.com/flutter-it/flutter_it/llms.txt Register services and dependencies using GetIt's service locator pattern for dependency injection. Supports singleton, lazy singleton, and factory registrations. ```dart import 'package:flutter_it/flutter_it.dart'; final getIt = GetIt.instance; void setup() { // Register singleton services getIt.registerSingleton(ApiService()); // Register lazy singletons (created on first access) getIt.registerLazySingleton(() => DatabaseService()); // Register factory (new instance each time) getIt.registerFactory(() => Logger()); } // Access registered services anywhere void someFunction() { final api = getIt(); final db = getIt(); } ``` -------------------------------- ### Asynchronous Commands with command_it Source: https://context7.com/flutter-it/flutter_it/llms.txt Create commands for asynchronous operations with built-in support for loading states, error handling, and execution control. Allows for managing the lifecycle of async tasks. ```dart import 'package:flutter_it/flutter_it.dart'; // Create an async command with initial value final loginCommand = Command.createAsync( (credentials) async { final result = await apiLogin(credentials); return result.success; }, initialValue: false, ); // Execute the command await loginCommand.run(LoginCredentials( username: 'user@example.com', password: 'password123', )); // Check command state if (loginCommand.isRunning) { print('Login in progress...'); } if (loginCommand.value) { print('Login successful!'); } // Handle errors if (loginCommand.errors.isNotEmpty) { print('Login failed: ${loginCommand.errors.last}'); } ``` -------------------------------- ### Reactive UI Updates with watch_it Source: https://context7.com/flutter-it/flutter_it/llms.txt Build reactive widgets that automatically rebuild when watched dependencies change. Utilizes WatchingWidget and watch functions to observe service or model value changes. ```dart import 'package:flutter_it/flutter_it.dart'; class MyWidget extends WatchingWidget { @override Widget build(BuildContext context) { // Watch a registered service for changes final api = watchIt(); // Watch a specific value from a model final data = watchValue((DataModel m) => m.value); return Text('Current value: $data'); } } ``` -------------------------------- ### Import flutter_it Package (Dart) Source: https://github.com/flutter-it/flutter_it/blob/main/README.md Demonstrates the single import statement required to access all functionalities from the flutter_it ecosystem. This simplifies your Dart code by consolidating multiple imports into one. ```dart import 'package:flutter_it/flutter_it.dart'; ``` -------------------------------- ### Add flutter_it Dependency (YAML) Source: https://github.com/flutter-it/flutter_it/blob/main/README.md This snippet shows how to add the flutter_it package as a dependency in your pubspec.yaml file. It replaces the need to add individual dependencies for get_it, watch_it, command_it, and listen_it. ```yaml dependencies: flutter_it: ^1.0.0 ``` -------------------------------- ### ValueListenable Operators with listen_it Source: https://context7.com/flutter-it/flutter_it/llms.txt Transform and filter ValueListenable streams using functional operators for reactive data processing. Enables chaining operations like `where` and `map` on observable values. ```dart import 'package:flutter_it/flutter_it.dart'; final itemsNotifier = ValueNotifier>([]); // Chain operators to transform data final filteredItems = itemsNotifier .where((items) => items.isNotEmpty) .map((items) => items.take(10).toList()); // Use in widgets class ItemListWidget extends WatchingWidget { @override Widget build(BuildContext context) { final items = watchValue((ValueNotifier> n) => n.value); return ListView.builder( itemCount: items.length, itemBuilder: (context, index) => ItemTile(item: items[index]), ); } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.