flet-stack


Nameflet-stack JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/fasilwdr/flet-stack
SummaryDecorator-based routing with view stacking for Flet applications
upload_time2025-10-06 08:20:42
maintainerNone
docs_urlNone
authorFasil
requires_python>=3.8
licenseMIT
keywords flet routing router navigation ui view-stack
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # flet-stack

**Decorator-based routing with automatic view stacking for Flet applications.**

[![PyPI version](https://badge.fury.io/py/flet-stack.svg)](https://badge.fury.io/py/flet-stack)
[![Python versions](https://img.shields.io/pypi/pyversions/flet-stack.svg)](https://pypi.org/project/flet-stack/)
[![PyPI Downloads](https://static.pepy.tech/personalized-badge/flet-stack?period=total&units=INTERNATIONAL_SYSTEM&left_color=GREY&right_color=BLUE&left_text=downloads)](https://pepy.tech/projects/flet-stack)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

## Features

- 🎯 **Decorator-based routing** - Clean, intuitive `@view()` decorator for route definitions
- 📚 **Automatic view stacking** - Navigate `/users/123/profile` and get a stack of 3 views
- 🔄 **State management** - Built-in state classes with `StateView` integration
- âš¡ **Async support** - Handle async data loading with automatic loading indicators
- 🎨 **URL parameters** - Extract parameters from routes like `/user/{id}`
- 🚀 **Zero configuration** - Just replace `ft.run()` with auto-routing enabled

## Installation

### From PyPI

```bash
pip install flet-stack
```

### From GitHub

```bash
pip install git+https://github.com/fasilwdr/flet-stack.git
```

### Install Specific Version

```bash
pip install git+https://github.com/fasilwdr/flet-stack.git@v0.1.0
```

### From Source

```bash
git clone https://github.com/fasilwdr/flet-stack.git
cd flet-stack
pip install .
```

## Quick Start

```python
import flet as ft
from flet_stack import view

# Define your routes with the @view decorator
@view("/")
def home_view(page):
    return ft.Column([
        ft.Text("Home Page", size=30),
        ft.Button("Go to Profile", on_click=lambda _: page.go("/profile")),
    ])

@view("/profile")
def profile_view(page):
    return ft.Column([
        ft.Text("Profile Page", size=30),
        ft.Button("Back", on_click=lambda _: page.go("/")),
    ])

# Run your app with auto-routing
def main(page: ft.Page):
    page.title = "My Flet App"
    page.go("/")  # Navigate to home

ft.run(target=main)
```

That's it! The routing is automatically enabled.

## Advanced Usage

### URL Parameters

Extract parameters from your routes:

```python
@view("/user/{user_id}")
def user_view(page, user_id):
    return ft.Column([
        ft.Text(f"User Profile: {user_id}", size=30),
        ft.Button("Back", on_click=lambda _: page.go("/")),
    ])
```

### State Management

Use state classes to manage component state:

```python
class CounterState:
    def __init__(self):
        self.count = 0

@view("/counter", state_class=CounterState)
def counter_view(state, page):
    def increment(e):
        state.count += 1
        page.update()
    
    return ft.Column([
        ft.Text(f"Count: {state.count}", size=30),
        ft.Button("Increment", on_click=increment),
    ])
```

### Async Data Loading

Load data asynchronously before showing your view:

```python
class UserState:
    def __init__(self):
        self.user_data = None

async def load_user_data(state, user_id):
    # Simulate API call
    await asyncio.sleep(1)
    state.user_data = {"id": user_id, "name": f"User {user_id}"}

@view("/user/{user_id}", state_class=UserState, on_load=load_user_data)
def user_detail_view(state, page, user_id):
    return ft.Column([
        ft.Text(f"Name: {state.user_data['name']}", size=20),
        ft.Text(f"ID: {state.user_data['id']}", size=16),
    ])
```

While loading, a progress indicator is automatically displayed.

### View Configuration

Pass additional Flet view properties:

```python
@view(
    "/settings",
    horizontal_alignment=ft.CrossAxisAlignment.CENTER,
    vertical_alignment=ft.MainAxisAlignment.CENTER,
    padding=20,
)
def settings_view(page):
    return ft.Text("Settings", size=30)
```

### View Stacking

Routes automatically create a navigation stack. Navigating to `/users/123/profile` creates:
- View 1: `/users`
- View 2: `/users/123`
- View 3: `/users/123/profile`

This enables natural back navigation in your app.

## How It Works

**flet-stack** patches `ft.run()` to automatically enable routing when your app starts. It:

1. Registers all `@view` decorated functions
2. Intercepts route changes
3. Builds a view stack from the URL path
4. Handles state management and async loading
5. Renders your views with proper navigation support

## Examples

Check the `examples/` directory for more detailed examples:
- `basic_example.py` - Simple routing and navigation
- `advanced_example.py` - State management, async loading, and URL parameters

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Acknowledgments

Built on top of the amazing [Flet](https://docs.flet.dev) framework.

## Support

If you encounter any issues or have questions:
- Open an issue on [GitHub](https://github.com/fasilwdr/flet-stack/issues)
- Check the [examples](examples/) directory
- Read the [Flet documentation](https://docs.flet.dev/)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/fasilwdr/flet-stack",
    "name": "flet-stack",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "flet, routing, router, navigation, ui, view-stack",
    "author": "Fasil",
    "author_email": "Fasil <fasilwdr@hotmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/34/16/5ad6153ca437cdf15b38937830209bf86ddbd374a860f05bca5818d21385/flet_stack-0.1.0.tar.gz",
    "platform": null,
    "description": "# flet-stack\n\n**Decorator-based routing with automatic view stacking for Flet applications.**\n\n[![PyPI version](https://badge.fury.io/py/flet-stack.svg)](https://badge.fury.io/py/flet-stack)\n[![Python versions](https://img.shields.io/pypi/pyversions/flet-stack.svg)](https://pypi.org/project/flet-stack/)\n[![PyPI Downloads](https://static.pepy.tech/personalized-badge/flet-stack?period=total&units=INTERNATIONAL_SYSTEM&left_color=GREY&right_color=BLUE&left_text=downloads)](https://pepy.tech/projects/flet-stack)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n## Features\n\n- \ud83c\udfaf **Decorator-based routing** - Clean, intuitive `@view()` decorator for route definitions\n- \ud83d\udcda **Automatic view stacking** - Navigate `/users/123/profile` and get a stack of 3 views\n- \ud83d\udd04 **State management** - Built-in state classes with `StateView` integration\n- \u26a1 **Async support** - Handle async data loading with automatic loading indicators\n- \ud83c\udfa8 **URL parameters** - Extract parameters from routes like `/user/{id}`\n- \ud83d\ude80 **Zero configuration** - Just replace `ft.run()` with auto-routing enabled\n\n## Installation\n\n### From PyPI\n\n```bash\npip install flet-stack\n```\n\n### From GitHub\n\n```bash\npip install git+https://github.com/fasilwdr/flet-stack.git\n```\n\n### Install Specific Version\n\n```bash\npip install git+https://github.com/fasilwdr/flet-stack.git@v0.1.0\n```\n\n### From Source\n\n```bash\ngit clone https://github.com/fasilwdr/flet-stack.git\ncd flet-stack\npip install .\n```\n\n## Quick Start\n\n```python\nimport flet as ft\nfrom flet_stack import view\n\n# Define your routes with the @view decorator\n@view(\"/\")\ndef home_view(page):\n    return ft.Column([\n        ft.Text(\"Home Page\", size=30),\n        ft.Button(\"Go to Profile\", on_click=lambda _: page.go(\"/profile\")),\n    ])\n\n@view(\"/profile\")\ndef profile_view(page):\n    return ft.Column([\n        ft.Text(\"Profile Page\", size=30),\n        ft.Button(\"Back\", on_click=lambda _: page.go(\"/\")),\n    ])\n\n# Run your app with auto-routing\ndef main(page: ft.Page):\n    page.title = \"My Flet App\"\n    page.go(\"/\")  # Navigate to home\n\nft.run(target=main)\n```\n\nThat's it! The routing is automatically enabled.\n\n## Advanced Usage\n\n### URL Parameters\n\nExtract parameters from your routes:\n\n```python\n@view(\"/user/{user_id}\")\ndef user_view(page, user_id):\n    return ft.Column([\n        ft.Text(f\"User Profile: {user_id}\", size=30),\n        ft.Button(\"Back\", on_click=lambda _: page.go(\"/\")),\n    ])\n```\n\n### State Management\n\nUse state classes to manage component state:\n\n```python\nclass CounterState:\n    def __init__(self):\n        self.count = 0\n\n@view(\"/counter\", state_class=CounterState)\ndef counter_view(state, page):\n    def increment(e):\n        state.count += 1\n        page.update()\n    \n    return ft.Column([\n        ft.Text(f\"Count: {state.count}\", size=30),\n        ft.Button(\"Increment\", on_click=increment),\n    ])\n```\n\n### Async Data Loading\n\nLoad data asynchronously before showing your view:\n\n```python\nclass UserState:\n    def __init__(self):\n        self.user_data = None\n\nasync def load_user_data(state, user_id):\n    # Simulate API call\n    await asyncio.sleep(1)\n    state.user_data = {\"id\": user_id, \"name\": f\"User {user_id}\"}\n\n@view(\"/user/{user_id}\", state_class=UserState, on_load=load_user_data)\ndef user_detail_view(state, page, user_id):\n    return ft.Column([\n        ft.Text(f\"Name: {state.user_data['name']}\", size=20),\n        ft.Text(f\"ID: {state.user_data['id']}\", size=16),\n    ])\n```\n\nWhile loading, a progress indicator is automatically displayed.\n\n### View Configuration\n\nPass additional Flet view properties:\n\n```python\n@view(\n    \"/settings\",\n    horizontal_alignment=ft.CrossAxisAlignment.CENTER,\n    vertical_alignment=ft.MainAxisAlignment.CENTER,\n    padding=20,\n)\ndef settings_view(page):\n    return ft.Text(\"Settings\", size=30)\n```\n\n### View Stacking\n\nRoutes automatically create a navigation stack. Navigating to `/users/123/profile` creates:\n- View 1: `/users`\n- View 2: `/users/123`\n- View 3: `/users/123/profile`\n\nThis enables natural back navigation in your app.\n\n## How It Works\n\n**flet-stack** patches `ft.run()` to automatically enable routing when your app starts. It:\n\n1. Registers all `@view` decorated functions\n2. Intercepts route changes\n3. Builds a view stack from the URL path\n4. Handles state management and async loading\n5. Renders your views with proper navigation support\n\n## Examples\n\nCheck the `examples/` directory for more detailed examples:\n- `basic_example.py` - Simple routing and navigation\n- `advanced_example.py` - State management, async loading, and URL parameters\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Acknowledgments\n\nBuilt on top of the amazing [Flet](https://docs.flet.dev) framework.\n\n## Support\n\nIf you encounter any issues or have questions:\n- Open an issue on [GitHub](https://github.com/fasilwdr/flet-stack/issues)\n- Check the [examples](examples/) directory\n- Read the [Flet documentation](https://docs.flet.dev/)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Decorator-based routing with view stacking for Flet applications",
    "version": "0.1.0",
    "project_urls": {
        "Documentation": "https://github.com/fasilwdr/flet-stack#readme",
        "Homepage": "https://github.com/fasilwdr/flet-stack",
        "Issues": "https://github.com/fasilwdr/flet-stack/issues",
        "Repository": "https://github.com/fasilwdr/flet-stack"
    },
    "split_keywords": [
        "flet",
        " routing",
        " router",
        " navigation",
        " ui",
        " view-stack"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "3645d3d5c42377e64a3d1f4b2c24518d8ee9620a8665913035be95f942e65106",
                "md5": "2cbd7668dd9cb391f53ee0d795e9f4d8",
                "sha256": "bf2868c2e24d8b2c205db3157f4d4fe6e3a7238eefbbc375f79f7e2078deb4d6"
            },
            "downloads": -1,
            "filename": "flet_stack-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2cbd7668dd9cb391f53ee0d795e9f4d8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 6472,
            "upload_time": "2025-10-06T08:20:41",
            "upload_time_iso_8601": "2025-10-06T08:20:41.669376Z",
            "url": "https://files.pythonhosted.org/packages/36/45/d3d5c42377e64a3d1f4b2c24518d8ee9620a8665913035be95f942e65106/flet_stack-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "34165ad6153ca437cdf15b38937830209bf86ddbd374a860f05bca5818d21385",
                "md5": "3f5d009c9f34b6b1eefb497792798d25",
                "sha256": "efac0a60e36dc8710b81b48ce67e7461f23afd6a13d5a0e09ac2ae485f6754bb"
            },
            "downloads": -1,
            "filename": "flet_stack-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "3f5d009c9f34b6b1eefb497792798d25",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 7241,
            "upload_time": "2025-10-06T08:20:42",
            "upload_time_iso_8601": "2025-10-06T08:20:42.932755Z",
            "url": "https://files.pythonhosted.org/packages/34/16/5ad6153ca437cdf15b38937830209bf86ddbd374a860f05bca5818d21385/flet_stack-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-10-06 08:20:42",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "fasilwdr",
    "github_project": "flet-stack",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "flet-stack"
}
        
Elapsed time: 2.65525s