Welcome to Neostate! ๐ A lightweight and intuitive library for managing shared states in Flet applications. With StateCraft, you can bind widgets to a shared state effortlessly, enabling seamless updates across your UI components with minimal boilerplate.
Project description
๐ฅNeostate ๐จโจ
Neostate is a package designed to simplify and optimize state management in Flet apps. It provides a clean and easy way to handle global and scoped states, allowing you to build apps with a simpler and more powerful state management system.
Elegant Routing ,State Management & More for Flet Applications
Welcome to Neostate! ๐ A lightweight and intuitive library for managing shared states in Flet applications,Use routing with Ease and much more, With Neostate, you can bind widgets to a shared state effortlessly, enabling seamless updates across your UI components with minimal boilerplate.
๐ก Installation
Install the package from PyPI:
pip install Neostate
๐ Shared State ๐
๐ StateNotifier Class
What is it?
Think of StateNotifier like a magic box where we store important information, like a score in a game. When the score changes, it shouts out to everyone that it's been updated!
How it works:
- We create a StateNotifier with a starting score.
- If the score changes, StateNotifier tells everyone whoโs listening, like other parts of your app, to update and show the new score!
Fun part ๐: You can add or remove listeners, like telling certain parts of the app to pay attention when the score changes.
๐ง Features
- ๐ Reactive State Management: Automatically update UI components when the state changes.
- ๐ช Simple Widget Binding: Use the
Sharedclass to bind Flet widgets dynamically to shared states. - ๐ง Formatter Support: Customize how state values are displayed with flexible formatting strings.
- ๐ Complex Widget Attributes: Update attributes like
content,value, orcontrolsdynamically. - โณ Detachable Listeners: Add or remove widgets from state listeners as needed.
- ๐ Inline State Updates: Use intuitive operations like
shared_state.value += 1. - ๐ Easy to Learn and Use: Minimal learning curve with a clean, developer-friendly
๐ Shared Class
What is it?
Imagine you have a cool widget (like a score display) and you want it to automatically change when the score updates. Shared makes this happen!
How it works:
- Shared links the score widget to the StateNotifier (the magic box from above).
- When the score changes, the widget instantly updates itself to show the new score. No need to do anything manually!
Whatโs special ๐ซ:
- If you have a special formatting (like showing the score as โScore: 10โ), you can tell Shared to format it for you.
- It will always keep the widget in sync with the score!
๐งโ๐ซ How They Work Together:
- StateNotifier keeps the score (or any value) safe.
- Shared makes sure your widgets (like score displays) stay updated with the new value whenever it changes!
Itโs like a team where one member holds the information (StateNotifier) and the other makes sure everything looks correct and up-to-date (Shared).
And thatโs how you make your app super interactive! ๐ฎ
Let me know if you'd like more details or adjustments! ๐๐
Routing Modes ๐ฅ
Basic Routing ๐ถโโ๏ธ
Basic routing allows you to manage navigation between pages in a simple way, using predefined methods like swap, reach, back, and refresh.
How it works:
here function means : the function which return ui like return [ft.Container(height=100) ]
- swap(route, function): This method adds a new page to the views stack and navigates to it. It appends the new view without removing the existing ones.
- reach(route, function): This method replaces the entire view stack with a new page.
- back(): This method allows you to go back to the previous view.
- refresh(): This method refreshes the current view.
To activate Basic Routing, you just need to call the app with advanced_routing=False:
enhanced_app(target, advanced_routing=False)
Example:
def home_page(page):
return Column([Text("Welcome to Home!")])
def about_page(page):
return Column([Text("About Us")])
# Basic Routing with swap and reach methods
page.swap("/home", home_page)
page.reach("/about", about_page)
Advanced Routing ๐
Advanced routing gives you more control by using RoutingConfig to register routes, middlewares, and error pages. This mode is ideal for complex applications where you need more flexibility.
How it works:
- RoutingConfig.register_route: Register routes with optional guards, custom redirects, and custom error pages.
- apply_middlewares: Apply middleware functions to routes for conditions like authentication.
- Global error pages: Define custom error pages for "404", "not allowed", etc.
To activate Advanced Routing, you call the app with advanced_routing=True:
enhanced_app(target, advanced_routing=True)
Example:
page.register_route("/home", home_page)
page.register_route("/about", about_page)
page.set_global_error_page("404", page_not_found)
page.register_middleware(auth_middleware)
Switch Between Routing Modes ๐
You can easily switch between Basic and Advanced routing modes:
-
For Basic Routing, set
advanced_routing=False:enhanced_app(target, advanced_routing=False)
-
For Advanced Routing, set
advanced_routing=True:enhanced_app(target, advanced_routing=True)
When to Choose Which? ๐ค
๐ Basic Routing: Best for mobile and desktop apps, providing simple and fast navigation.
๐๏ธ Advanced Routing: Perfect for websites and web apps, supporting complex setups with middleware and role-based access.
Extras
Hereโs the updated changelog with the emojis added back in:
-
๐ ๏ธ Neostate App Creation Command
Creating a new app template is now easier than ever! Use theneostate create appnamecommand in the terminal to generate your app structure. Here's the generated directory structure:<appname>/ โโโ assets/ โ โโโ fonts/ โ โโโ images/ โโโ App/ โ โโโ components/ โ โโโ pages/ โ โโโ services/ โ โโโ state/ โ โโโ utils/ โ โโโ main.py โโโ main.py โโโ requirements.txt โโโ README.md
Just Use this command inside terminal/cmd in empty folder
Neostate create <appname>
<appname> can be anything like firstapp
- ๐ฏ Center Widget Support
Added aCenterwidget to simplify centering any widget. Whether it's aColumn,Row, orContainersimply wrap it withCenter(ft.column([]))to achieve perfect centering. Theforceandexpandarguments are optional.
#usage
from Neostate Import Center
Center(ft.Column([]) #or can be any widget
)
it has two optional argument force and expand , True or False can be passed , test it out yourself
Enjoy these new features to enhance your app development workflow!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file neostate-0.1.4.1.tar.gz.
File metadata
- Download URL: neostate-0.1.4.1.tar.gz
- Upload date:
- Size: 13.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78278b7af7906013305752f580e410ee9c335aebfd2f3a1fab371f2649f4c641
|
|
| MD5 |
2ce5c7eca3851c39263aaadf4380ba6f
|
|
| BLAKE2b-256 |
704a8ac5697116b09442b5273960ba216d407ddeb86d52e09b38dd2d1481e331
|
File details
Details for the file Neostate-0.1.4.1-py3-none-any.whl.
File metadata
- Download URL: Neostate-0.1.4.1-py3-none-any.whl
- Upload date:
- Size: 14.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3d7b640aaee10fd3b0928ca1987a256614d48cd2cdb0ea26be2c9355df223bed
|
|
| MD5 |
07254d4bf9cee4ce44f15e110399f02a
|
|
| BLAKE2b-256 |
483f2526599fb9064c04db7df72bb13b396309964bfeb54ff1fe44b4003f4041
|