Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Middlewares to AddPagesy #37

Open
1 task done
Daxexs opened this issue Feb 10, 2025 · 0 comments
Open
1 task done

Add Middlewares to AddPagesy #37

Daxexs opened this issue Feb 10, 2025 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@Daxexs
Copy link
Owner

Daxexs commented Feb 10, 2025

  • Add Middlewares to AddPagesy. which will be automatically integrated into all decorated pages.

To use Middleware in AddPagesy is very easy, you can do it in two ways (both support async):

  • Function: It only supports the use before request and has as parameter data:fs.Datasy.

  • Class: It has to be inherited from fs.MiddlewareRequest, which contains two very interesting methods before_request and after_request, you can use the attribute data:fs.Datasy.

Example:

import flet_easy as fs
import flet as ft

class CustomMiddleware(fs.MiddlewareRequest):
    def before_request(self):
        print("+ Before request", self.data.page.title)

    async def after_request(self):
        print("+ After request")

async def use_middleware(data: fs.Datasy):
    print("+ Use middleware before request", data.history_routes)

tools = fs.AddPagesy(
    middlewares=[CustomMiddleware, use_middleware],
)

@tools.page(route="/home", title="Tools-Flet-Easy")
async def index_page(data: fs.Datasy):
    return ft.View(
        controls=[
            ft.Text("Home page"),
        ]
    )

@tools.page(route="/test", title="Test-Flet-Easy")
def test_page(data: fs.Datasy):
    return ft.View(
        controls=[
            ft.Text("Test page"),
        ]
    )
@Daxexs Daxexs added the enhancement New feature or request label Feb 10, 2025
@Daxexs Daxexs self-assigned this Feb 10, 2025
@Daxexs Daxexs moved this to In progress in Flet-Easy Development Feb 14, 2025
@Daxexs Daxexs moved this from In progress to In review in Flet-Easy Development Mar 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: In review
Development

No branches or pull requests

1 participant