|
1 | | -<h1 align="center">FletNavigator V2.0.1</h1> |
| 1 | +<h1 align="center">FletNavigator V2.1.1</h1> |
2 | 2 | <i><p align="center">Simple and fast navigator (router) for Flet (Python) that allows you to create multi-page applications! [<code>pip install flet_navigator</code>].<br><b>[<a href="https://github.com/xzripper/flet_navigator/blob/main/flet-navigator-docs.md">DOCUMENTATION</a>].</b></p> |
3 | 3 | <p align="center">Using Example: |
4 | 4 |
|
5 | 5 | ```python |
6 | | -from flet import app, Page, Text, FilledButton, TextThemeStyle |
| 6 | +from flet import app, Page |
7 | 7 |
|
8 | | -from flet_navigator import VirtualFletNavigator, Any, ROUTE_404 |
| 8 | +from flet_navigator import VirtualFletNavigator, PageData, Any, ROUTE_404 |
9 | 9 |
|
10 | | -from random import randint |
| 10 | +def main_page(pg: PageData) -> None: |
| 11 | + ... # Main page content. |
11 | 12 |
|
| 13 | +def second_page(pg: PageData) -> None: |
| 14 | + ... # Second page content. |
12 | 15 |
|
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. |
18 | | -def main_page(page: Page, navigator: VirtualFletNavigator, args: tuple[Any]) -> None: |
19 | | - page.add(Text('Main Page!', style=TextThemeStyle.DISPLAY_MEDIUM)) |
| 16 | +def route_404(pg: PageData) -> None: |
| 17 | + ... # 404 Page Content. |
20 | 18 |
|
21 | | - if args: |
22 | | - page.add(Text(f'Message from {args[0]}: {args[1]}.')) |
23 | | - |
24 | | - page.add( |
25 | | - FilledButton( |
26 | | - 'Navigate to second page!', |
27 | | - |
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! |
29 | | - ) |
30 | | - ) |
31 | | - |
32 | | - page.add( |
33 | | - FilledButton( |
34 | | - 'Navigate to really_non_existent_page!', |
35 | | - |
36 | | - on_click=lambda _: navigator.navigate('really_non_existent_page', page) # Navigate to non-existent page. Will result route_404. |
37 | | - ) |
38 | | - ) |
39 | | - |
40 | | -# Second page content. |
41 | | -def second_page(page: Page, navigator: VirtualFletNavigator, args: tuple[Any]) -> None: |
42 | | - page.add(Text('Second Page!', style=TextThemeStyle.DISPLAY_SMALL)) |
43 | | - |
44 | | - page.add(Text(f'Message from {args[0]}: {args[1]}')) |
45 | | - |
46 | | - page.add( |
47 | | - FilledButton( |
48 | | - 'Navigate to main page!', |
49 | | - |
50 | | - on_click=lambda _: navigator.navigate('/', page, ('second page', randint(1, 100))) # Navigate to main page, and send random number as arguments! |
51 | | - ) |
52 | | - ) |
53 | | - |
54 | | -# 404 page content. |
55 | | -def route_404(page: Page, navigator: VirtualFletNavigator, args: tuple[Any]) -> None: |
56 | | - page.add(Text('How did you get here? There is no page like this registered in routes...')) |
57 | | - |
58 | | - page.add( |
59 | | - FilledButton( |
60 | | - 'Navigate to the main page until it is too late...', |
61 | | - |
62 | | - on_click=lambda _: navigator.navigate('/', page) # Navigate to main page. |
63 | | - ) |
64 | | - ) |
65 | | - |
66 | | -# Main function. Being used only for routing. |
67 | 19 | def main(page: Page) -> None: |
68 | 20 | # Initialize navigator. |
69 | 21 | flet_navigator = VirtualFletNavigator( |
70 | 22 | { |
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). |
| 23 | + '/': main_page, # Main page route. |
| 24 | + 'second_page': second_page, # Second page route. |
| 25 | + ROUTE_404: route_404 # 404 page route. |
| 26 | + }, lambda route: print(f'Route changed!: {route}') # Route change handler (optional). |
75 | 27 | ) |
76 | 28 |
|
77 | | - flet_navigator.render(page) # Render main page. |
| 29 | + flet_navigator.render(page) # Render current page. |
78 | 30 |
|
79 | | -app(target=main) # Run main fuction. |
| 31 | +app(target=main) |
80 | 32 | ``` |
81 | 33 |
|
82 | 34 | </p> |
83 | 35 |
|
84 | | -<p align="center"><img src="example.gif" width=600></p> |
85 | | - |
86 | | -~~There is no documentation, or more examples, because you can use FletNavigator just by researching this small example! Also every function, and class field has own docstring.<br> |
87 | | -This example will be updated in next releases to keep everything up to date.~~ |
| 36 | +<p align="center"><img src="example.gif" width=500></p> |
88 | 37 |
|
89 | 38 | See the difference between ```VirtualFletNavigator``` and ```FletNavigator```, and more <a href="https://github.com/xzripper/flet_navigator/blob/main/flet-navigator-docs.md">here</a> (<- documentation). |
90 | 39 |
|
91 | 40 | <hr> |
92 | | -<p align="center">FletNavigator v2.0.1.</p></i> |
| 41 | +<p align="center">FletNavigator v2.1.1.</p></i> |
0 commit comments