๐Ÿš€ zeba_academy_state_machine

A lightweight, powerful Finite State Machine (FSM) for Flutter.

Designed to help you manage application states safely, prevent invalid transitions, and debug state flows easily โ€” without unnecessary complexity.


โœจ Features

  • ๐Ÿ”„ Define states and transitions
  • ๐Ÿ›‘ Prevent invalid state changes
  • ๐Ÿง  Lightweight & simple architecture
  • ๐Ÿงช Fully testable
  • ๐Ÿงพ Built-in debug logging
  • โšก High performance with minimal overhead

๐Ÿ“ฆ Installation

Add this to your pubspec.yaml:

dependencies:
  zeba_academy_state_machine: ^0.0.1

Then run:

flutter pub get

๐Ÿš€ Quick Start

import 'package:zeba_academy_state_machine/zeba_academy_state_machine.dart';

final idle = ZState('idle');
final loading = ZState('loading');
final success = ZState('success');

final machine = ZStateMachine(initialState: idle)
  ..addState(loading)
  ..addState(success)
  ..addTransition(idle, loading)
  ..addTransition(loading, success);

machine.transitionTo(loading);
machine.transitionTo(success);

๐Ÿง  Core Concepts

๐Ÿ”น State

Represents a condition of your app.

final idle = ZState('idle');

๐Ÿ”น Transition

Defines valid movement between states.

machine.addTransition(idle, loading);

๐Ÿ”น State Machine

Controls the flow and ensures only valid transitions occur.

machine.transitionTo(loading);

๐Ÿ›ก Prevent Invalid Transitions

machine.transitionTo(success); // โŒ Throws exception if invalid

๐Ÿงช Debugging

Built-in debugger logs all transitions:

machine.debugger.logs.forEach(print);

Example output:

โœ… idle โ†’ loading
โŒ INVALID: loading โ†’ idle

๐ŸŽฏ Use Cases

  • UI state management
  • Authentication flows
  • API request lifecycle
  • Form validation flows
  • Game logic
  • Workflow engines

๐Ÿ”ฅ Advanced Usage

Listen to Transitions

machine.onTransition = (from, to) {
  print('Transitioned from $from to $to');
};

Check Before Transition

if (machine.canTransition(success)) {
  machine.transitionTo(success);
}

๐Ÿงช Testing

Run tests using:

flutter test

๐Ÿ›ฃ Roadmap

  • ๐Ÿ“Š Visual state graph
  • ๐Ÿ” Undo / redo transitions
  • โณ Async transitions support
  • ๐Ÿ”Œ Integration with Bloc / Riverpod
  • ๐Ÿงฐ DevTools extension

๐Ÿ“„ License

This project is licensed under the GNU General Public License v3.0.


๐Ÿ‘จโ€๐Ÿ’ป About Me

โœจ Iโ€™m Sufyan bin Uzayr, an open-source developer passionate about building and sharing meaningful projects. You can learn more about me and my work at sufyanism.com or connect with me on Linkedin


๐ŸŒ Your all-in-one no-bloat hub!

๐Ÿš€ Explore cutting-edge resources in coding, tech, and development at zeba.academy and code.zeba.academy. Empower yourself with practical skills through curated directives, real-world projects, and hands-on experience. Level up your tech game today! ๐Ÿ’ปโœจ

Zeba Academy is a learning platform dedicated to coding, technology, and development. โžก Visit our main site: zeba.academy โžก Explore hands-on courses and resources at: code.zeba.academy โžก Check out our YouTube for more tutorials: zeba.academy โžก Follow us on Instagram: zeba.academy


โค๏ธ Support

If you like this package, consider giving it a โญ on GitHub and sharing it with the community!


Thank you for visiting! ๐Ÿ™Œ