minix 1.1.0
minix: ^1.1.0 copied to clipboard
A powerful, lightweight state management and dependency injection solution for Flutter applications with reactive programming capabilities.
Minix π #
A powerful, lightweight state management and dependency injection solution for Flutter applications. Minix provides reactive programming capabilities with minimal boilerplate and maximum performance.
Built with β€οΈ by Jai Prakash Thawait #
β¨ Features #
- π₯ Reactive State Management - Observable values that automatically update UI
- π Dependency Injection - Lightweight service locator with advanced features
- β‘ Performance Optimized - Minimal rebuilds, maximum efficiency
- π― Type Safe - Full Dart type safety with generics
- π Async Support - Built-in async operations handling
- π‘ Stream Integration - Reactive stream management
- π§ ComputedObservable for derived state that auto-updates when dependencies change.
- β‘οΈ runInAction to batch multiple updates into a single reactive transaction.
- π·οΈ Tagged Dependencies - Multiple instances with tags
- π Scoped Injection - Scope-based lifecycle management
- π§ͺ Testing Friendly - Easy mocking and overrides
- π± Flutter Optimized - Designed specifically for Flutter widgets
π Quick Start #
π¦ Installation #
Add the following line to your pubspec.yaml
:
dependencies: minix: ^1.1.0
Basic Usage #
import 'package:minix/minix.dart';
// 1. Create observable state final counter = Observable(0);
// 2. Use in widgets class CounterWidget extends StatelessWidget { @override Widget build(BuildContext context) { return Observer(() => Text('Count: ${counter.value}')); } }
// 3. Update state counter.value++; // UI automatically rebuilds
π Core Components #
π Observer Widget Automatically rebuilds when observables change:
Observer(() { return Column( children: [ Text('Counter: ${counter.value}'), Text('Name: ${userName.value}'), ], ); })
π― ContextObserver Widget #
Observer with BuildContext access:
ContextObserver((context) { return Container( width: MediaQuery.of(context).size.width, child: Text('Responsive: ${counter.value}'), ); })
β‘ Observable #
Reactive state container: // Create observable final userName = Observable
// Read value (reactive in Observer) final name = userName.value;
// Update value userName.value = 'Jane'; // Triggers UI rebuild
// Non-reactive read final currentName = userName.read();
π AsyncObservable #
Handle async operations with built-in loading states:
final userService = AsyncObservable
// Execute async operation await userService.execute(() async { return await api.fetchUser(); });
// Use in UI Observer(() { if (userService.isLoading) return CircularProgressIndicator(); if (userService.hasError) return Text('Error: ${userService.error}'); if (userService.hasData) return UserWidget(userService.data!); return Text('No data'); })
AsyncObservable States #
// Check states
userService.watchLoading() // bool - reactive
userService.watchData() // T? - reactive
userService.watchError() // String? - reactive
userService.watchState() // AsyncState - reactive
// Manual control userService.setData(user); userService.setError('Network error'); userService.reset();
π‘ StreamObservable #
Reactive stream management:
final chatMessages = StreamObservable
// Listen to stream chatMessages.listen( messageStream, onData: (message) => print('New message: $message'), onError: (error) => print('Stream error: $error'), );
// Use in UI Observer(() { return ListView.builder( itemCount: chatMessages.hasData ? 1 : 0, itemBuilder: (context, index) { return MessageTile(chatMessages.data!); }, ); })
// Stream operations final filteredMessages = chatMessages .where((msg) => msg.isImportant) .map((msg) => msg.content);
// Control stream chatMessages.pause(); chatMessages.resume(); await chatMessages.cancel();
π Dependency Injection #
Basic Registration
// Register instance Injector.put
// Lazy registration Injector.lazyPut
// Async registration await Injector.putAsync
// Find dependencies final api = Injector.find
Advanced Features #
// Auto dispose (automatic cleanup) Injector.autoDisposePut
// Scoped injection Injector.putScoped
// Tagged instances (multiple instances of same type) Injector.putTagged
final fileLogger = Injector.findTagged
// Testing overrides Injector.override
Injectable Interface #
class MyService implements Injectable { @override void onInit() { print('Service initialized'); }
@override void onDispose() { print('Service disposed'); } }
ποΈ Architecture Patterns #
MVVM with Minix
// ViewModel class UserViewModel { final _user = Observable<User?>(null); final _userAsync = AsyncObservable
User? get user => _user.value; AsyncObservable
Future
// Register ViewModel Injector.lazyPut
// View class UserScreen extends StatelessWidget { @override Widget build(BuildContext context) { final viewModel = Injector.find
return Observer(() {
if (viewModel.userAsync.isLoading) {
return CircularProgressIndicator();
}
return Column(
children: [
Text('User: ${viewModel.user?.name ?? 'Unknown'}'),
ElevatedButton(
onPressed: () => viewModel.loadUser('123'),
child: Text('Load User'),
),
],
);
});
} }
Repository Pattern #
abstract class UserRepository { Future
class ApiUserRepository implements UserRepository { final ApiService _api = Injector.find
@override Future
@override Stream<List
// Registration Injector.put
π― Performance Tips #
- Use Observer wisely - Wrap only widgets that need reactivity
- Read vs Value - Use observable.read() for non-reactive access
- Dispose resources - Always dispose observables and streams
- Lazy registration - Use lazyPut for heavy services
- Scoped dependencies - Use scopes for lifecycle management
π Debugging #
Enable logging to track dependency injection:
void main() { Injector.enableLogs = true; Injector.onEvent = (event, type) { print('DI Event: $event for $type'); };
runApp(MyApp()); }
// Debug current dependencies Injector.debugPrintDependencies();
π± Platform Support
β Android β iOS β Web β Desktop (Windows, macOS, Linux)
π€ Contributing We welcome contributions! Please see our Contributing Guide for details. π License This project is licensed under the MIT License - see the LICENSE file for details. πββοΈ Support
π Documentation π Issues π¬ Discussions
π Examples Find complete examples in our examples directory:
π± Counter App π API Integration π Todo List with MVVM π Real-time Chat π§ͺ Testing Examples
Made with β€οΈ for the Flutter community