speedex 0.0.2 copy "speedex: ^0.0.2" to clipboard
speedex: ^0.0.2 copied to clipboard

SpeedEx, short for "Speed Execution" is a lightweight and simple state management solution for Flutter, offering global state handling with minimal boilerplate.

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

Installation #

Add SpeedEx to your pubspec.yaml file:

dependencies:
  speedex: ^0.0.2

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'),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

Contributing #

Contributions are welcome! Please feel free to submit a Pull Request.

License #

This project is licensed under the MIT License - see the LICENSE file for details.

5
likes
160
points
25
downloads

Publisher

verified publishermo-shaheen.wuaze.com

Weekly Downloads

SpeedEx, short for "Speed Execution" is a lightweight and simple state management solution for Flutter, offering global state handling with minimal boilerplate.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on speedex