Skip to main content

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 ๐ŸŽจโœจ

githubpypi

image image uv linting - Ruff Downloads

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 Shared class 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, or controls dynamically.
  • โณ 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! ๐Ÿ˜Š๐Ÿ“š

Explore Documentation

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) ]

  1. 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.
  2. reach(route, function): This method replaces the entire view stack with a new page.
  3. back(): This method allows you to go back to the previous view.
  4. 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:
  1. RoutingConfig.register_route: Register routes with optional guards, custom redirects, and custom error pages.
  2. apply_middlewares: Apply middleware functions to routes for conditions like authentication.
  3. 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 the neostate create appname command 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 a Center widget to simplify centering any widget. Whether it's a Column, Row, or Container simply wrap it with Center(ft.column([])) to achieve perfect centering. The force and expand arguments 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

neostate-0.1.4.0.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

Neostate-0.1.4.0-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file neostate-0.1.4.0.tar.gz.

File metadata

  • Download URL: neostate-0.1.4.0.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

Hashes for neostate-0.1.4.0.tar.gz
Algorithm Hash digest
SHA256 8008d8832c7d171f76c42be03dd33fe86c85b55d14605b29094f7d447aeead3a
MD5 2ae28f8951bf91897523518a65843685
BLAKE2b-256 c0d10b341038b6b14e7800f1a63f9e33a6e09396af33cbdaf68977447189a3da

See more details on using hashes here.

File details

Details for the file Neostate-0.1.4.0-py3-none-any.whl.

File metadata

  • Download URL: Neostate-0.1.4.0-py3-none-any.whl
  • Upload date:
  • Size: 14.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for Neostate-0.1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b5dbe599a9bad9ea54496959243aac46fff8d797596d8872d0739aefa41ab138
MD5 d5e0eb706c86aef65cae6977dd02bc56
BLAKE2b-256 afb0c676421505fe81c47d28849f7cff04d48a8fd7a75a0782efc2024cde7bab

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page