This makes it easy to manage multiple views with dynamic routing.
Project description
This makes it easy to manage multiple views with dynamic routing.
This is an utility class based on repath library which allows matching ExpressJS-like routes and parsing their parameters, for example /account/:account_id/orders/:order_id
.
Installation
pip install flet-route
Upgradation
pip install flet-route --upgrade
function based view:
main.py
import flet as ft
from flet_route import Routing,path
from views.index_view import IndexView
from views.next_view import NextView
def main(page: ft.Page):
app_routes = [
path(url="/", clear=True, view=IndexView),
path(url="/next_view/:my_id", clear=False, view=NextView),
]
Routing(page=page,app_routes=app_routes)
page.go(page.route)
ft.app(target=main)
views/index_view.py
import flet as ft
def IndexView(page,params):
print(params)
return ft.View(
"/",
controls=[
ft.Text("This Is Index View"),
ft.ElevatedButton("Go Next View", on_click=lambda _: page.go("/next_view/10")),
]
)
views/next_view.py
import flet as ft
def NextView(page,params):
print(params)
return ft.View(
"/next_view/:my_id",
controls=[
ft.Text("This Is Next View"),
ft.ElevatedButton("Go Index View", on_click=lambda _: page.go("/")),
]
)
Class based view:
main.py
import flet as ft
from flet_route import Routing,path
from views.index_view import IndexView
from views.next_view import NextView
def main(page: ft.Page):
app_routes = [
path(url="/", clear=True, view=IndexView().view),
path(url="/next_view/:my_id", clear=False, view=NextView().view),
]
Routing(page=page,app_routes=app_routes)
page.go(page.route)
ft.app(target=main)
views/index_view.py
import flet as ft
class IndexView:
def __init__(self):
...
def view(self,page,params):
print(params)
return ft.View(
"/",
controls=[
ft.Text("This Is Index View"),
ft.ElevatedButton("Go Next View", on_click=lambda _: page.go("/next_view/10")),
]
)
views/next_view.py
import flet as ft
class NextView:
def __init__(self):
...
def view(self,page,params):
print(params)
return ft.View(
"/next_view/:my_id",
controls=[
ft.Text("This Is Next View"),
ft.ElevatedButton("Go Index View", on_click=lambda _: page.go("/")),
]
)
Author
Name : Saurabh Wadekar
Email : saurabhwadekar420@gmail.com
County : 🇮🇳INDIA🇮🇳
❤️ THANK YOU ❤️
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
flet_route-0.1.3.tar.gz
(3.5 kB
view hashes)
Built Distribution
Close
Hashes for flet_route-0.1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | de866b1d65b6bee84044805ffe01000b785a13810d4072f697b789bc82f84439 |
|
MD5 | 09c491918cc3a349f9d78c2e6959ddeb |
|
BLAKE2b-256 | a6ca42dcbaccf56c56cd7308eec27efe672fb77e5a316207150b3229d2bf2c0f |