Skip to content

Commit 803ab41

Browse files
authored
Documentation update.
Documentation update.
1 parent e8f4d06 commit 803ab41

File tree

1 file changed

+72
-24
lines changed

1 file changed

+72
-24
lines changed

flet-navigator-docs.md

Lines changed: 72 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
<h1 align="center">FletNavigator v2.0.1 Documentation.</h1>
1+
<h1 align="center">FletNavigator v2.1.1 Documentation.</h1>
22

33
<h4 align="center">Menu:</h4>
44

55
- [Getting Started.](#getting-started)
66
- [General.](#general)
77
- [`VirtualFletNavigator`](#virtualfletnavigator)
88
- [`FletNavigator`](#fletnavigator)
9+
- [`define_page`](#define_page)
910
- [Summary.](#summary)
1011

1112
<hr>
@@ -23,18 +24,18 @@ Installation is quite easy: ```pip install flet_navigator```
2324
- **✨ Fast.**
2425
- **✨ Cookies-like mechanism.**
2526
- **✨ Animations between page change. (FUTURE).**
26-
- **✨ Built-in smart URL parameters parser. (Not fully implemented).**
27+
- **✨ Built-in smart URL parameters parser.**
2728
- **✨ Multiple routing modes.**
2829
- **✨ And more! And even more coming in future!**
2930

3031
**FletNavigator TODO**:
3132
- **Animations between page change.**
32-
- **Implement URL parameters for `navigate`.**
33+
- ~**Implement URL parameters for `navigate`.**~
3334
- **Fix bugs.**
3435

3536
**FletNavigator Known Bugs**:
36-
- **Double redirect when using `navigate` (class `FletNavigator`).**
37-
- **Unable to trace previous page when manually updating URL in browser (`_nav_route_change_handler`).**
37+
- ~**Double redirect when using `navigate` (class `FletNavigator`).**~
38+
- **Unable to trace previous page when manually updating URL in browser (`_nav_route_change_handler`). (Seems like fixed).**
3839
- **Non-tested in real projects.**
3940

4041
<hr>
@@ -71,24 +72,19 @@ Route should have latin alphabet (no cyrillic), route can have underscores and d
7172

7273
```flet_navigator::constructor:51: Warning: Wrong route name: "$my_route1У H". Allowed only digits and underscores.```
7374

74-
<br>
75-
76-
- **Page definition.**
77-
<img src="doc_media_1.png">
78-
7975
<hr>
8076

8177
<h3 align="center"><code>VirtualFletNavigator</code></h3>
8278

8379
- `VirtualFletNavigator` - Virtual Flet Navigator Class.
8480
- `route: str = '/'` - Current route.
85-
- `routes: dict[str, Callable[[Page, 'VirtualFletNavigator', tuple[Any], str], None]] = {}` - Registered routes.
81+
- `routes: dict[str, Callable[[PageData], None]] = {}` - Registered routes.
8682
- `routes_data: dict[str, Any] = {}` - Routes data.
8783
- `route_changed_handler: Callable[[str], None] = None` - Route changed handler.<br><br>
8884

8985
- `__init__(routes: dict[str, Callable[[Page, 'VirtualFletNavigator', tuple[Any], str], None]], route_changed_handler: Callable[[str], None]=None) -> None` - Initialize Virtual Flet Navigator.
90-
- `navigate(route: str, page: Page, args: tuple[Any]=None, route_parameters: dict[str, Any]={}) -> None` - Navigate to specific route. Specify `args` to transfer arguments to other page.
91-
- `render(page: Page, args: tuple[Any]=None, route_parameters: dict[str, Any]={}) -> None` - Render current route. If there is no route like that throw ROUTE-404 (if specified). Should be called only one time.
86+
- `navigate(route: str, page: Page, args: tuple[Any]=None) -> None` - Navigate to specific route. Specify `args` to transfer arguments to other page.
87+
- `render(page: Page, args: tuple[Any]=None) -> None` - Render current route. If there is no route like that throw ROUTE-404 (if specified). Should be called only one time.
9288
- `set_route_data(self, route: str, data: Any) -> int` - Set route data (cookies-like mechanism). Returns success/fail.
9389
- `get_route_data(self, route: str) -> Any` - Get route data.
9490

@@ -97,15 +93,15 @@ Using example:
9793
```python
9894
from flet import app, Page
9995

100-
from flet_navigator import VirtualFletNavigator, Any, ROUTE_404
96+
from flet_navigator import VirtualFletNavigator, PageData, Any, ROUTE_404
10197

102-
def main_page(page: Page, navigator: VirtualFletNavigator, args: tuple[Any], previous: str, parameters: dict[str, Any]) -> None:
98+
def main_page(pg: PageData) -> None:
10399
... # Main page content.
104100

105-
def second_page(page: Page, navigator: VirtualFletNavigator, args: tuple[Any], previous: str, parameters: dict[str, Any]) -> None:
101+
def second_page(pg: PageData) -> None:
106102
... # Second page content.
107103

108-
def route_404(page: Page, navigator: VirtualFletNavigator, args: tuple[Any], previous: str, parameters: dict[str, Any]) -> None:
104+
def route_404(pg: PageData) -> None:
109105
... # 404 Page Content.
110106

111107
def main(page: Page) -> None:
@@ -130,12 +126,12 @@ app(target=main)
130126
- `FletNavigator` - Flet Navigator Class.
131127
- `page: Page = None` - Page.
132128
- `route: str = '/'` - Current route.
133-
- `routes: dict[str, Callable[[Page, 'VirtualFletNavigator', tuple[Any], str], None]] = {}` - Registered routes.
129+
- `routes: dict[str, Callable[[PageData], None]] = {}` - Registered routes.
134130
- `routes_data: dict[str, Any] = {}` - Routes data.
135131
- `route_changed_handler: Callable[[str], None] = None` - Route changed handler.<br><br>
136132

137133
- `__init__(page: Page, routes: dict[str, Callable[[Page, 'VirtualFletNavigator', tuple[Any], str], None]], route_changed_handler: Callable[[str], None]=None) -> None` - Initialize Flet Navigator.
138-
- `navigate(route: str, page: Page, args: tuple[Any]=None, route_parameters: dict[str, Any]={}) -> None` - Navigate to specific route. Specify `args` to transfer arguments to other page.
134+
- `navigate(route: str, page: Page, args: tuple[Any]=None) -> None` - Navigate to specific route. Specify `args` to transfer arguments to other page.
139135
- `render(page: Page, args: tuple[Any]=None, route_parameters: dict[str, Any]={}) -> None` - Render current route. If there is no route like that throw ROUTE-404 (if specified). Should be called only one time.
140136
- `set_route_data(self, route: str, data: Any) -> int` - Set route data (cookies-like mechanism). Returns success/fail.
141137
- `get_route_data(self, route: str) -> Any` - Get route data.
@@ -148,13 +144,13 @@ from flet import app, Page, WEB_BROWSER
148144
from flet_navigator import FletNavigator, Any, ROUTE_404
149145

150146

151-
def main_page(page: Page, navigator: FletNavigator, args: tuple[Any], previous: str, parameters: dict[str, Any]) -> None:
147+
def main_page(pg: PageData) -> None:
152148
... # Main page content.
153149

154-
def second_page(page: Page, navigator: FletNavigator, args: tuple[Any], previous: str, parameters: dict[str, Any]) -> None:
150+
def second_page(pg: PageData) -> None:
155151
... # Second page content.
156152

157-
def route_404(page: Page, navigator: FletNavigator, args: tuple[Any], previous: str, parameters: dict[str, Any]) -> None:
153+
def route_404(pg: PageData) -> None:
158154
... # 404 page content.
159155

160156
def main(page: Page) -> None:
@@ -175,11 +171,63 @@ app(target=main, view=WEB_BROWSER) # Non-Virtual Navigator recommended in web.
175171

176172
<hr>
177173

174+
<h3 align="center"><code>define_page</code></h3>
175+
176+
```define_page(path: str, name: str=None) -> Callable[[PageData], None]```
177+
178+
Used to import page from other file. Example:<br><br>
179+
180+
`second_page.py`
181+
182+
```python
183+
# from flet import
184+
185+
from flet_navigator import PageData
186+
187+
188+
def second_page(pg: PageData) -> None:
189+
... # Second page content.
190+
```
191+
192+
<br>
193+
194+
`main.py`
195+
196+
```python
197+
from flet_navigator import FletNavigator
198+
199+
def main(page: Page) -> None:
200+
flet_navigator = FletNavigator(page,
201+
{
202+
'/': main_page,
203+
'second_page': define_page('second_page'),
204+
ROUTE_404: route_404
205+
}, lambda route: print(f'Route changed!: {route}')
206+
)
207+
208+
flet_navigator.render(page)
209+
210+
app(target=main, view=WEB_BROWSER) # Non-Virtual Navigator recommended in web.
211+
```
212+
213+
<br>
214+
215+
If `name` is None, `path` is used as page name.
216+
217+
```python
218+
define_page('second_page') # => second_page
219+
define_page('path\\to\\page\\second_page') # => second_page
220+
define_page('path/to/page/second_page') # => second_page
221+
define_page('second_page', 'my_second_page_name') # => my_second_page_name
222+
```
223+
224+
<hr>
225+
178226
<h3 align="center">Summary.</h3>
179-
Summary! Now you know difference between virtual and non-virtual navigator, how to use navigator, etc! Good luck, have fun! But remember that project isn't finished!
227+
Summary! Now you know difference between virtual and non-virtual navigator, how to use navigator, etc! Good luck, have fun! But remember that project isn't finished!<br><br>
180228

181229
*Developer Note*: It would be great support for me if you'd added credits for FletNavigator! Optional!
182230

183231
<hr>
184232

185-
<p align="center"><b><i>FletNavigator V2.0.1</i></b></p>
233+
<p align="center"><b><i>FletNavigator V2.1.1</i></b></p>

0 commit comments

Comments
 (0)