Skip to main content

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 # Here IndexView is imported from views/index_view.py
from views.next_view import NextView # Here NextView is imported from views/next_view.py

def main(page: ft.Page):

    app_routes = [
        path(
            url="/", # Here you have to give that url which will call your view on mach
            clear=True, # If you want to clear all the routes you have passed so far, then pass True otherwise False.
            view=IndexView # Here you have to pass a function or method which will take page and params and return ft.View (If you are using function based view then you just have to give the name of the function.)
            ), 
        path(url="/next_view/:my_id", clear=False, view=NextView),
    ]

    Routing(
        page=page, # Here you have to pass the page. Which will be found as a parameter in all your views
        app_routes=app_routes, # Here a list has to be passed in which we have defined app routing like app_routes
        #not_found_view:View=ViewNotFound # If you want that there should be a different view call when no path matches, then you can pass that view here. otherwise no need to give it it will call ViewNotFound by default
        )
    page.go(page.route)

ft.app(target=main)

views/index_view.py

This is a basic python function that takes page and params and returns ft.View.

In page we get the page passed in path.

In params we get the values ​​passed from url in the form of dictionary

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

This is a basic python function that takes page and params and returns ft.View.

In page we get the page passed in path.

In params we get the values ​​passed from url in the form of dictionary

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 # Here IndexView is imported from views/index_view.py
from views.next_view import NextView # Here NextView is imported from views/next_view.py

def main(page: ft.Page):

    app_routes = [
        path(
            url="/", # Here you have to give that url which will call your view on mach
            clear=True, # If you want to clear all the routes you have passed so far, then pass True otherwise False.
            view=IndexView().view # Here you have to pass a function or method which will take page and params and return ft.View (If you are using class based view then you have to pass method name like IndexView().view .)
            ),
        path(url="/next_view/:my_id", clear=False, view=NextView().view),
    ]

    Routing(
        page=page, # Here you have to pass the page. Which will be found as a parameter in all your views
        app_routes=app_routes, # Here a list has to be passed in which we have defined app routing like app_routes
        #not_found_view:View=ViewNotFound().view # If you want that there should be a different view call when no path matches, then you can pass that view here. otherwise no need to give it it will call ViewNotFound by default
        )
    page.go(page.route)

ft.app(target=main)

views/index_view.py

This is a basic python class whose view method takes page and params and returns ft.view.

In page we get the page passed in path.

In params we get the values ​​passed from url in the form of dictionary.

It is not necessary that the name of the method should be view, you can also give a different name.

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

This is a basic python class whose view method takes page and params and returns ft.view.

In page we get the page passed in path.

In params we get the values ​​passed from url in the form of dictionary.

It is not necessary that the name of the method should be view, you can also give a different name.

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


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.4.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

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

flet_route-0.1.4-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file flet_route-0.1.4.tar.gz.

File metadata

  • Download URL: flet_route-0.1.4.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for flet_route-0.1.4.tar.gz
Algorithm Hash digest
SHA256 9f6e657e0e8bf7055205c193879660a5316ad1281e239952be5138a5458918e9
MD5 39fa3e9162d83ae0b1dd1e469e274f81
BLAKE2b-256 642137f9d639b06f831f0b976c273968ae662af5582e40b0e117daccd8612c1a

See more details on using hashes here.

File details

Details for the file flet_route-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: flet_route-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for flet_route-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 79edfc4a2f8e568fbc48def31334f9ceb5eda97ecf819a346508736ac527aa64
MD5 c13dc1f3ad261ac59ba6cce56d1ccaf1
BLAKE2b-256 70fd65374069a7c897819cf6f003abe39a56b047d887c2f4daaf2d778f922483

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