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

A lightweight and simple state management solution for Flutter, offering global state handling with minimal boilerplate.

SpeedEx #

SpeedEx is a lightweight and simple state management solution for Flutter that provides global state handling with minimal boilerplate. It allows you to set, retrieve, and listen for changes to global state variables, making it ideal for small to medium-sized projects.

Features #

  • Global state management using a centralized state map.
  • Simple API to get, set, and listen to state changes.
  • Efficient state reactivity with listeners.
  • No dependencies on third-party packages.
  • Lightweight and easy to integrate into any Flutter project.

Installation #

Add the following to your pubspec.yaml file:

dependencies:
  speedex: ^0.0.1

Then run:

flutter pub get

Usage #

Setting Up a Global State #

import 'package:speedex/speedex.dart';

// Set a value in the global state
SpeedEx.setValue<int>('counter', 0);

// Retrieve a value from the global state
int counter = SpeedEx.getValue<int>('counter');

Listening to State Changes #

You can add listeners to react to state changes:

void myListener() {
  print('State has changed!');
}

// Add a listener to the 'counter' state
SpeedEx.addListener('counter', myListener);

// Remove the listener when it's no longer needed
SpeedEx.removeListener('counter', myListener);

Building Reactive Widgets #

SpeedExWidget helps you create reactive widgets that rebuild when the state changes:

SpeedExWidget<int>(
  stateKey: 'counter',
  builder: (context, value) {
    return Text('Counter value: $value');
  },
);

Example #

import 'package:flutter/material.dart';
import 'package:speedex/speedex.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: CounterScreen(),
    );
  }
}

class CounterScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('SpeedEx Counter')),
      body: Center(
        child: SpeedExWidget<int>(
          stateKey: 'counter',
          builder: (context, counter) {
            return Text('Counter: $counter');
          },
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          int counter = SpeedEx.getValue<int>('counter') ?? 0;
          SpeedEx.setValue<int>('counter', counter + 1);
        },
        child: Icon(Icons.add),
      ),
    );
  }
}

Performance Considerations #

  • Global State: While SpeedEx is simple and easy to use, it centralizes all states globally. This can lead to less optimization for complex apps with many state variables.
  • Efficient UI Rebuilds: SpeedExWidget ensures that only widgets that depend on the state are rebuilt when the state changes.

For performance-critical apps, consider using selective rebuilding patterns, and ensure listeners are added and removed correctly to prevent memory leaks.

Contributing #

Contributions are welcome! If you encounter any bugs or have feature requests, please open an issue or submit a pull request.

License #

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

5
likes
0
points
19
downloads

Publisher

verified publishermo-shaheen.wuaze.com

Weekly Downloads

A lightweight and simple state management solution for Flutter, offering global state handling with minimal boilerplate.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on speedex