@@ -10,6 +10,11 @@ from flet_navigator import FletNavigator, Any, ROUTE_404
1010from random import randint
1111
1212
13+ # Main page content.
14+ # page - Current page,
15+ # navigator - With this you can navigate to other pages,
16+ # args - Arguments sent from other page.
17+ # Using these all typehints is optional.
1318def main_page (page : Page, navigator : FletNavigator, args : tuple[Any]) -> None :
1419 page.add(Text(' Main Page!' , style = TextThemeStyle.DISPLAY_MEDIUM ))
1520
@@ -20,18 +25,19 @@ def main_page(page: Page, navigator: FletNavigator, args: tuple[Any]) -> None:
2025 FilledButton(
2126 ' Navigate to second page!' ,
2227
23- on_click = lambda _ : navigator.navigate(' second_page' , page, (' main page' , ' Hello from main page!' ))
28+ on_click = lambda _ : navigator.navigate(' second_page' , page, (' main page' , ' Hello from main page!' )) # Navigate to 'second_page', and send greetings from main page as arguments!
2429 )
2530 )
2631
2732 page.add(
2833 FilledButton(
2934 ' Navigate to really_non_existent_page!' ,
3035
31- on_click = lambda _ : navigator.navigate(' really_non_existent_page' , page)
36+ on_click = lambda _ : navigator.navigate(' really_non_existent_page' , page) # Navigate to non-existent page. Will result route_404.
3237 )
3338 )
3439
40+ # Second page content.
3541def second_page (page : Page, navigator : FletNavigator, args : tuple[Any]) -> None :
3642 page.add(Text(' Second Page!' , style = TextThemeStyle.DISPLAY_SMALL ))
3743
@@ -41,33 +47,36 @@ def second_page(page: Page, navigator: FletNavigator, args: tuple[Any]) -> None:
4147 FilledButton(
4248 ' Navigate to main page!' ,
4349
44- on_click = lambda _ : navigator.navigate(' /' , page, (' second page' , randint(1 , 100 )))
50+ on_click = lambda _ : navigator.navigate(' /' , page, (' second page' , randint(1 , 100 ))) # Navigate to main page, and send random number as arguments!
4551 )
4652 )
4753
54+ # 404 page content.
4855def route_404 (page : Page, navigator : FletNavigator, args : tuple[Any]) -> None :
4956 page.add(Text(' How did you get here? There is no page like this registered in routes...' ))
5057
5158 page.add(
5259 FilledButton(
5360 ' Navigate to the main page until it is too late...' ,
5461
55- on_click = lambda _ : navigator.navigate(' /' , page)
62+ on_click = lambda _ : navigator.navigate(' /' , page) # Navigate to main page.
5663 )
5764 )
5865
66+ # Main function. Being used only for routing.
5967def main (page : Page) -> None :
68+ # Initialize navigator.
6069 flet_navigator = FletNavigator(
6170 {
62- ' /' : main_page,
63- ' second_page' : second_page,
64- ROUTE_404 : route_404
65- }, lambda route : print (f ' Route changed!: { route} ' )
71+ ' /' : main_page, # Specify main page,
72+ ' second_page' : second_page, # Specify second page,
73+ ROUTE_404 : route_404 # Specify 404 page (optional).
74+ }, lambda route : print (f ' Route changed!: { route} ' ) # On route changed handler (optional).
6675 )
6776
68- flet_navigator.render(page)
77+ flet_navigator.render(page) # Render main page.
6978
70- app(target = main)
79+ app(target = main) # Run main fuction.
7180```
7281
7382</p >
0 commit comments