Created
July 24, 2022 15:16
-
-
Save mikaelho/79e7c182e724e5993ed8c424270dd65f to your computer and use it in GitHub Desktop.
Sample for moving between views
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import flet | |
from flet import AppBar | |
from flet import ElevatedButton | |
from flet import Icon | |
from flet import IconButton | |
from flet import Page | |
from flet import Text | |
from flet import View | |
from flet import icons | |
class FirstPage(View): | |
def __init__(self, page): | |
super().__init__( | |
'/', | |
[ | |
AppBar(title=Text("Flet app"), leading=Icon(icons.HOME)), | |
ElevatedButton("Go to settings", on_click=self.open_settings), | |
] | |
) | |
self.page = page | |
def open_settings(self, e): | |
self.page.views.append( | |
View( | |
"/settings", | |
[ | |
AppBar( | |
title=Text("Settings"), | |
leading=IconButton(icon=icons.CHEVRON_LEFT, on_click=self.pop_settings) | |
), | |
Text("Settings"), | |
], | |
) | |
) | |
self.page.update() | |
def pop_settings(self, e): | |
self.page.views.pop() | |
self.page.update() | |
def main(page: Page): | |
page.title = "Routes Example" | |
page.views.append(FirstPage(page)) | |
page.update() | |
flet.app(target=main) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment