Skip to content

Commit 88c3615

Browse files
committed
working mvp
1 parent 508305f commit 88c3615

File tree

12 files changed

+86
-0
lines changed

12 files changed

+86
-0
lines changed

main.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import flet as ft
2+
3+
from views.FletRouter import Router
4+
from user_controls.app_bar import NavBar
5+
6+
def main(page: ft.Page):
7+
8+
page.appbar = NavBar(page, ft)
9+
myRouter = Router(page, ft)
10+
11+
page.on_route_change = myRouter.route_change
12+
13+
page.add(
14+
myRouter.body
15+
)
16+
page.update()
17+
18+
19+
ft.app(target=main)
927 Bytes
Binary file not shown.

user_controls/app_bar.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import flet as ft
2+
3+
4+
def NavBar(page, ft=ft):
5+
6+
7+
8+
NavBar = ft.AppBar(
9+
leading=ft.Icon(ft.icons.TAG_FACES_ROUNDED),
10+
leading_width=40,
11+
title=ft.Text("Flet Router"),
12+
center_title=False,
13+
bgcolor=ft.colors.SURFACE_VARIANT,
14+
actions=[
15+
ft.IconButton(ft.icons.HOME, on_click=lambda _: page.go('/')),
16+
ft.IconButton(ft.icons.PERSON_ROUNDED, on_click=lambda _: page.go('/profile')),
17+
ft.IconButton(ft.icons.SETTINGS_ROUNDED, on_click=lambda _: page.go('/settings'))
18+
]
19+
)
20+
21+
return NavBar

views/FletRouter.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
import flet as ft # dev purposes only
3+
4+
# Nav Bar to give to views
5+
from user_controls.app_bar import NavBar
6+
7+
# views
8+
from views.index_view import IndexView
9+
from views.profile_view import ProfileView
10+
from views.settings_view import SettingsView
11+
12+
13+
14+
class Router:
15+
16+
def __init__(self, page, ft):
17+
self.page = page
18+
self.ft = ft
19+
self.routes = {
20+
"/": IndexView(),
21+
"/profile": ProfileView(),
22+
"/settings": SettingsView()
23+
}
24+
self.body = ft.Container(content=self.routes['/'])
25+
26+
def route_change(self, route):
27+
print(route.route)
28+
print(self.routes[route.route])
29+
self.body.content = self.routes[route.route]
30+
self.page.update()
1.02 KB
Binary file not shown.
303 Bytes
Binary file not shown.
310 Bytes
Binary file not shown.
1.01 KB
Binary file not shown.
313 Bytes
Binary file not shown.

views/index_view.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
import flet as ft
3+
4+
def IndexView(ft=ft):
5+
return ft.Text("This is the Home")
6+

0 commit comments

Comments
 (0)