zeba_academy_state_machine 0.0.1
zeba_academy_state_machine: ^0.0.1 copied to clipboard
Lightweight finite state machine for Flutter with validation and debugging.
๐ 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!
๐ Changelog #
0.0.1 Initial Release #
๐ First stable release of zeba_academy_state_machine
โจ Features
- Add
ZStatefor defining states - Add
ZTransitionfor state transitions - Implement
ZStateMachinecore engine - Support for adding states and transitions
- Prevent invalid transitions with runtime checks
canTransition()helper methodonTransitioncallback support
๐งช Debugging
- Built-in
ZDebuggerfor logging transitions - Logs for successful transitions
- Logs for invalid transitions
๐ก Safety
- Enforces state registration before transitions
- Throws exceptions for invalid transitions
โก Performance
- Lightweight architecture
- Minimal dependencies
๐ฆ Developer Experience
- Simple and clean API
- Easy integration with Flutter apps
- Test-friendly design
โค๏ธ Support #
If you like this package, consider giving it a โญ on GitHub and sharing it with the community!
Thank you for visiting! ๐