Nahrungstracker/app/main.py

49 lines
1.5 KiB
Python
Raw Normal View History

2024-06-23 14:02:09 +02:00
import flet as ft
2024-06-23 19:41:00 +02:00
from pages.home import Home
from pages.history import History
2024-06-23 14:02:09 +02:00
from pages.settings import Settings
2024-06-23 19:41:00 +02:00
from flet import app
2024-06-23 14:02:09 +02:00
def main(page: ft.Page):
page.title = "Nahrungstracker"
page.scroll = True
2024-06-23 19:41:00 +02:00
history_instance = History() # Erstellen der History-Instanz
home = Home(history_instance) # Übergeben der History-Instanz an Home
home.page = page
2024-06-23 14:02:09 +02:00
2024-06-23 19:41:00 +02:00
settings = Settings()
2024-06-23 14:02:09 +02:00
settings.page = page
def on_navigation_change(e):
page.controls.clear()
if e.control.selected_index == 0:
2024-06-23 19:41:00 +02:00
page.appbar = home.create_appbar()
page.add(home)
2024-06-23 14:02:09 +02:00
elif e.control.selected_index == 1:
2024-06-23 19:41:00 +02:00
page.appbar = ft.AppBar(title=ft.Text("History"))
history_instance.update_history_view()
page.add(history_instance) # Hinzufügen der History-Instanz zur Seite
elif e.control.selected_index == 2:
2024-06-23 14:02:09 +02:00
page.appbar = ft.AppBar(title=ft.Text("Settings"))
page.add(settings)
page.update()
page.navigation_bar = ft.NavigationBar(
destinations=[
ft.NavigationDestination(icon=ft.icons.HOME, label="Home"),
2024-06-23 19:41:00 +02:00
ft.NavigationDestination(icon=ft.icons.HISTORY, label="History"),
2024-06-23 14:02:09 +02:00
ft.NavigationDestination(icon=ft.icons.SETTINGS, label="Settings")
],
on_change=on_navigation_change,
)
2024-06-23 19:41:00 +02:00
page.appbar = home.create_appbar()
page.add(home)
page.update()
2024-06-23 14:02:09 +02:00
if __name__ == "__main__":
2024-06-23 19:41:00 +02:00
print("run")
app(target=main)