import flet as ft from pages.root import Nahrung from pages.settings import Settings def main(page: ft.Page): page.title = "Nahrungstracker" page.scroll = True # Initialize views nahrung = Nahrung() settings = Settings() # Store reference to the page in instances nahrung.page = page settings.page = page # Function to switch views def on_navigation_change(e): page.controls.clear() if e.control.selected_index == 0: page.appbar = nahrung.create_appbar() page.add(nahrung) elif e.control.selected_index == 1: 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"), ft.NavigationDestination(icon=ft.icons.SETTINGS, label="Settings") ], on_change=on_navigation_change, ) page.appbar = nahrung.create_appbar() page.add(nahrung) page.update() # Ensure the initial UI is updated if __name__ == "__main__": ft.app(target=main)