SpeedEx
SpeedEx, short for Speed Execution is a lightweight and efficient state management solution for Flutter applications. Designed with performance in mind, SpeedEx offers a simple yet powerful way to manage global state across your app with minimal boilerplate.
Features
- 🚀 Fast and efficient state management
- 🌐 Global state accessible from anywhere in your app
- 🧮 Support for computed values
- 🔄 Built-in undo functionality
- 🔍 State change history tracking
- 🔒 Persistence support
- 🔗 Middleware for intercepting state changes
- 📦 Simple API with a single widget for state consumption
- 📱 Available on Android, iOS, Web, Windows, macOS, and Linux
Installation
Add SpeedEx to your pubspec.yaml
file or install via pub.dev:
dependencies:
speedex: ^0.0.3
Then run:
flutter pub get
Usage
Initializing SpeedEx
Before using SpeedEx, make sure to initialize it in your main.dart
:
import 'package:speedex/speedex.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await SpeedEx.initialize();
runApp(MyApp());
}
Setting and Getting Values
// Set a value
await SpeedEx.setValue('counter', 0);
// Get a value
int counter = SpeedEx.getValue<int>('counter') ?? 0;
Using SpeedExWidget
SpeedExWidget is the primary way to consume state in your UI:
SpeedExWidget<int>(
stateKey: 'counter',
builder: (context, value) {
return Text('Counter: ${value ?? 0}');
},
initialValue: 0,
persist: true,
)
Computed Values
SpeedEx.setComputedValue<int>('doubleCounter', () {
return (SpeedEx.getValue<int>('counter') ?? 0) * 2;
});
Undo Functionality
await SpeedEx.undo();
Middleware
SpeedEx.addMiddleware((key, oldValue, newValue) async {
print('State changed: $key, $oldValue -> $newValue');
});
Full Example
import 'package:flutter/material.dart';
import 'package:speedex/speedex.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await SpeedEx.initialize();
SpeedEx.addMiddleware((key, oldValue, newValue) async {
print('State changed: $key, $oldValue -> $newValue');
});
await SpeedEx.setValue('counter', 0, persist: true);
SpeedEx.setComputedValue<int>('doubleCounter', () {
return (SpeedEx.getValue<int>('counter') ?? 0) * 2;
});
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('SpeedEx Demo')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SpeedExWidget<int>(
stateKey: 'counter',
builder: (context, value) {
return Text('Counter: ${value ?? 0}');
},
),
SpeedExWidget<int>(
stateKey: 'doubleCounter',
builder: (context, value) {
return Text('Double Counter: ${value ?? 0}');
},
),
ElevatedButton(
onPressed: () async {
int currentValue = SpeedEx.getValue<int>('counter') ?? 0;
await SpeedEx.setValue('counter', currentValue + 1, persist: true);
},
child: Text('Increment'),
),
ElevatedButton(
onPressed: SpeedEx.undo,
child: Text('Undo'),
),
],
),
),
),
);
}
}
Documentation
For detailed documentation, visit the SpeedEx Wiki.
Issues
Found a bug or have a feature request? Please visit our Issues Page to report it.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For issues and feature requests, check out our Issues Page.
License
This project is licensed under the MIT License - see the LICENSE file for details. For a full overview of the MIT license, you can also view it here.