minix 1.0.0 copy "minix: ^1.0.0" to clipboard
minix: ^1.0.0 copied to clipboard

A powerful, lightweight state management and dependency injection solution for Flutter applications with reactive programming capabilities.

Minix Banner

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
  • 🏷️ 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.0.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

2
likes
0
points
33
downloads

Publisher

unverified uploader

Weekly Downloads

A powerful, lightweight state management and dependency injection solution for Flutter applications with reactive programming capabilities.

Repository (GitHub)
View/report issues

Topics

#state-management #dependency-injection #reactive-programming #flutter #observables

License

unknown (license)

Dependencies

flutter

More

Packages that depend on minix