swift_flutter 1.0.0
swift_flutter: ^1.0.0 copied to clipboard
A reactive state management library for Flutter with automatic dependency tracking, computed values, async state, form validation, and more.
swift_flutter #
A reactive state management library for Flutter with automatic dependency tracking. Inspired by MobX and Vue's reactivity system, but built specifically for Flutter.
Features #
✅ Reactive State (Rx) - Automatic dependency tracking
✅ Mark Widget - Auto-rebuild when dependencies change
✅ Computed (Derived State) - Automatically computed values with nested dependency support
✅ RxFuture / Async State - Loading/error/success states for async operations
✅ Form Validation - Field validation with built-in validators
✅ Persistence - Automatic save/load of reactive values
✅ Middleware / Interceptors - Action interception and logging
✅ Batch Update Transactions - Prevent unnecessary rebuilds
✅ Debug Logger - Configurable logging with history
✅ Animation Tween - Reactive animation values
✅ Lifecycle Controller - Widget lifecycle management
✅ Global Store / Dependency Injection - Service registration and state management
Installation #
Add this to your package's pubspec.yaml file:
dependencies:
swift_flutter: ^1.0.0
Then run:
flutter pub get
Quick Start #
Basic Reactive State #
import 'package:swift_flutter/swift_flutter.dart';
// Create reactive state
final counter = Rx<int>(0);
// Use in widget with automatic rebuild
Mark(
builder: (context) => Text('Count: ${counter.value}'),
)
// Update value - widget rebuilds automatically!
counter.value = 10;
Computed Values #
final price = Rx<double>(100.0);
final quantity = Rx<int>(2);
// Automatically recomputes when price or quantity changes
final total = Computed(() => price.value * quantity.value);
Mark(
builder: (context) => Text('Total: \$${total.value}'),
)
Async State #
final rxFuture = RxFuture<String>();
// Execute async operation
rxFuture.execute(() async {
await Future.delayed(Duration(seconds: 2));
return 'Data loaded!';
});
// Display state
Mark(
builder: (context) => rxFuture.value.when(
idle: () => Text('Click to load'),
loading: () => CircularProgressIndicator(),
success: (data) => Text(data),
error: (error, stack) => Text('Error: $error'),
),
)
Form Validation #
final emailField = RxField<String>('');
emailField.addValidator(Validators.required());
emailField.addValidator(Validators.email());
TextField(
onChanged: (value) => emailField.value = value,
decoration: InputDecoration(
errorText: emailField.error,
),
)
Documentation #
- Full API Documentation
- Architecture Review
- Performance Comparison
Example #
See the example directory for a complete example app demonstrating all features.
Run the example:
cd example
flutter run
Testing #
All features include comprehensive test coverage:
flutter test
58 tests passing ✅
Contributing #
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License #
This project is licensed under the MIT License - see the LICENSE file for details.
Author #
Support #
If you find this package useful, please consider giving it a ⭐ on pub.dev and GitHub!