quick_change 1.0.1 copy "quick_change: ^1.0.1" to clipboard
quick_change: ^1.0.1 copied to clipboard

A simple, lightweight quick state-management package for Flutter.

quick_change ๐Ÿงฉ #

A lightweight, intuitive state management solution for Flutter.
Effortlessly manage state transitions with simple, type-safe states and powerful listening and building capabilities.

Version License Flutter


quick_change is designed to simplify state management in Flutter apps, making it suitable for both small and medium-scale applications, with the flexibility to extend for large apps. This package provides easy-to-use state controllers, built-in state types, and intuitive UI listening and building capabilities.

Features โœจ #

  • Simple and Lightweight: Manage state without heavy dependencies.
  • Flexible States: Use predefined states like QuickLoading, QuickData, and QuickError.
  • Easy Listeners: React to state changes with a clean, intuitive listener API.
  • Modular Design: Suitable for modular and scalable Flutter applications.
  • Optimized for Performance: Only rebuilds widgets when necessary.

Table of Contents ๐Ÿ“š #


Installation #

Add quick_change to your pubspec.yaml:

dependencies:
  quick_change: ^1.0.0

Then run:

flutter pub get

Quick Start ๐Ÿš€ #

  1. Define a QuickChangeController to manage your state.
  2. Use QuickChangeBuilder to listen to state changes and update the UI.
  3. Use .quickListen to respond to state changes outside of rebuilds.

API Overview #

  • QuickStateController: Manages state changes and notifies listeners.
  • States:
    • QuickInitial: Represents the initial state.
    • QuickLoading: Represents a loading state.
    • QuickData<T>: Holds data of type T.
    • QuickError: Represents an error state with a message.
  • QuickStateBuilder: A widget that builds UI based on the controllerโ€™s state.
  • .quickListen: An extension on widgets to listen to state changes without rebuilding.

Examples #

Basic Counter Example #

Hereโ€™s how to create a simple counter using quick_state.

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

class CounterScreen extends StatefulWidget {
  @override
  _CounterScreenState createState() => _CounterScreenState();
}

class _CounterScreenState extends State<CounterScreen> {
  final QuickChangeController<int> counterController = QuickChangeController<int>();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("Counter Example")),
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          QuickChangeBuilder<int>(
            controller: counterController,
            onInitial: (context) => Text("Welcome! Tap the button to start."),
            onLoading: (context) => CircularProgressIndicator(),
            onData: (context, data) => Text("Counter: $data", style: TextStyle(fontSize: 24)),
            onError: (context, message) => Text("Error: $message"),
          ),
          SizedBox(height: 20),
          ElevatedButton(
            onPressed: () {
              counterController.setLoading();
              Future.delayed(Duration(seconds: 1), () {
                final currentValue = counterController.getCurrentData() ?? 0;
                counterController.setData(currentValue + 1);
              });
            },
            child: Text("Increment Counter"),
          ),
        ],
      ),
    );
  }
}

Listening for Errors #

You can use .quickListen to display a Custom message such as SnackBar when an error occurs.



  // Listen for errors
 Widget.quickListen(
      controller: counterController,
      listener: (state) {
        if (state is QuickError) {
          ScaffoldMessenger.of(context).showSnackBar(
            SnackBar(content: Text(state.message)),
          );
        }
      },
    );
}

Advanced Usage #

Custom State Types #

Define custom states by extending QuickState.

class QuickSuccess extends QuickState {
  final String message;
  QuickSuccess(this.message);
}

counterController.setSuccess(String message) {
  _state = QuickSuccess(message);
  notifyListeners();
}

Middleware and Logging #

Add logging to track state changes.

void quickListenWithLogging<T>({
  required QuickStateController<T> controller,
  required void Function(QuickState state) listener,
}) {
  controller.addListener(() {
    print("State changed to: ${controller.state}");
    listener(controller.state);
  });
}

Contributing ๐Ÿค #

We welcome contributions! Please read our Contributing Guide for more details on how to get involved.


License ๐Ÿ“„ #

This project is licensed under the MIT License. See the LICENSE file for more details.


Happy coding! ๐Ÿ˜Š๐ŸŽ‰ With quick_state & Farooq , managing Flutter state transitions has never been simpler.

1
likes
0
points
27
downloads

Publisher

unverified uploader

Weekly Downloads

A simple, lightweight quick state-management package for Flutter.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on quick_change