Nahrungstracker/app/main.py

50 lines
1.6 KiB
Python
Raw Permalink 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()
2024-07-02 18:44:27 +02:00
#test = ft.NavigationBarDestination(icon=ft.icons.HOME, label="Home")
2024-06-23 14:02:09 +02:00
page.navigation_bar = ft.NavigationBar(
destinations=[
2024-07-02 18:44:27 +02:00
ft.NavigationBarDestination(icon=ft.icons.HOME, label="Home"),
ft.NavigationBarDestination(icon=ft.icons.HISTORY, label="History"),
ft.NavigationBarDestination(icon=ft.icons.SETTINGS, label="Settings")
2024-06-23 14:02:09 +02:00
],
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)