Skip to content

Commit 9d3ae0a

Browse files
authored
Documentation.
Documentation.
1 parent 369d964 commit 9d3ae0a

File tree

1 file changed

+71
-15
lines changed

1 file changed

+71
-15
lines changed

flet-navigator-docs.md

Lines changed: 71 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
<h1 align="center">FletNavigator v2.1.1 Documentation.</h1>
1+
<h1 align="center">FletNavigator v2.2.3 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+
- [`PageData`](#pagedata)
910
- [`define_page`](#define_page)
11+
- [`template`](#template)
1012
- [Summary.](#summary)
1113

1214
<hr>
1315

1416
<h3 align="center">Getting Started.</h3>
15-
FletNavigator - Simple and fast navigator (router) for Flet (Python) that allows you to create multi-page applications!<br>It allows you to define own routes, provides built-in URL parameters support, animations (in-future), virtual routing, and more...<br><br>
17+
FletNavigator - Simple and fast navigator (router) for Flet (Python) that allows you to create multi-page applications!<br>It allows you to define own routes, provides built-in URL parameters support, animations, virtual routing, and more...<br><br>
1618

1719
Installation is quite easy: ```pip install flet_navigator```
1820

@@ -23,18 +25,18 @@ Installation is quite easy: ```pip install flet_navigator```
2325
- **✨ Simple installation and very simple using.**
2426
- **✨ Fast.**
2527
- **✨ Cookies-like mechanism.**
26-
- **✨ Animations between page change. (FUTURE).**
28+
- **✨ Animations between page change.**
2729
- **✨ Built-in smart URL parameters parser.**
2830
- **✨ Multiple routing modes.**
31+
- **✨ Templates.**
32+
- **✨ MVC Support.**
2933
- **✨ And more! And even more coming in future!**
3034

3135
**FletNavigator TODO**:
32-
- **Animations between page change.**
33-
- ~**Implement URL parameters for `navigate`.**~
36+
- **Animations between page change. (50%).**
3437
- **Fix bugs.**
3538

3639
**FletNavigator Known Bugs**:
37-
- ~**Double redirect when using `navigate` (class `FletNavigator`).**~
3840
- **Unable to trace previous page when manually updating URL in browser (`_nav_route_change_handler`). (Seems like fixed).**
3941
- **Non-tested in real projects.**
4042

@@ -72,28 +74,49 @@ Route should have latin alphabet (no cyrillic), route can have underscores and d
7274

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

77+
<br>
78+
79+
- **Homepages.**
80+
81+
Homepage is main page, that you can set with `set_homepage`, and navigate with `navigate_homepage`.
82+
83+
<br>
84+
85+
- **Typehints.**
86+
87+
- `Arguments = tuple[Any]` - Arguments type.
88+
- `PageDefinition = Callable[[PageData], None]` - Page definition type.
89+
- `TemplateDefinition = Callable[[PageData, Arguments], None]` - Template definition type.
90+
- `RouteChangedHandler = Callable[[str], None]` - Route changed handler type.
91+
- `Routes = dict[str, PageDefinition]` - Routes type.
92+
7593
<hr>
7694

7795
<h3 align="center"><code>VirtualFletNavigator</code></h3>
7896

7997
- `VirtualFletNavigator` - Virtual Flet Navigator Class.
8098
- `route: str = '/'` - Current route.
81-
- `routes: dict[str, Callable[[PageData], None]] = {}` - Registered routes.
99+
- `routes: Routes = {}` - Registered routes.
82100
- `routes_data: dict[str, Any] = {}` - Routes data.
83-
- `route_changed_handler: Callable[[str], None] = None` - Route changed handler.<br><br>
101+
- `homepage: str = '/'` - Homepage (main page).
102+
- `fade_effect: bool = True` - Use fade effect when switching pages? BETA.
103+
- `route_changed_handler: RouteChangedHandler = None` - Route changed handler.<br><br>
84104

85105
- `__init__(routes: dict[str, Callable[[Page, 'VirtualFletNavigator', tuple[Any], str], None]], route_changed_handler: Callable[[str], None]=None) -> None` - Initialize Virtual Flet Navigator.
86106
- `navigate(route: str, page: Page, args: tuple[Any]=None) -> None` - Navigate to specific route. Specify `args` to transfer arguments to other page.
107+
- `navigate_homepage(page: Page, args: tuple[Any]=None) -> None` - Navigate to homepage.
87108
- `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.
88109
- `set_route_data(self, route: str, data: Any) -> int` - Set route data (cookies-like mechanism). Returns success/fail.
89110
- `get_route_data(self, route: str) -> Any` - Get route data.
111+
- `set_homepage(self, homepage: str) -> None` - Set homepage (main page).
90112

91113
Using example:
92114

93115
```python
94116
from flet import app, Page
95117

96-
from flet_navigator import VirtualFletNavigator, PageData, Any, ROUTE_404
118+
from flet_navigator import VirtualFletNavigator, PageData, ROUTE_404
119+
97120

98121
def main_page(pg: PageData) -> None:
99122
... # Main page content.
@@ -126,22 +149,26 @@ app(target=main)
126149
- `FletNavigator` - Flet Navigator Class.
127150
- `page: Page = None` - Page.
128151
- `route: str = '/'` - Current route.
129-
- `routes: dict[str, Callable[[PageData], None]] = {}` - Registered routes.
152+
- `routes: Routes = {}` - Registered routes.
130153
- `routes_data: dict[str, Any] = {}` - Routes data.
131-
- `route_changed_handler: Callable[[str], None] = None` - Route changed handler.<br><br>
154+
- `homepage: str = '/'` - Homepage (main page).
155+
- `fade_effect: bool = True` - Use fade effect when switching pages? BETA.
156+
- `route_changed_handler: RouteChangedHandler = None` - Route changed handler.<br><br>
132157

133158
- `__init__(page: Page, routes: dict[str, Callable[[Page, 'VirtualFletNavigator', tuple[Any], str], None]], route_changed_handler: Callable[[str], None]=None) -> None` - Initialize Flet Navigator.
134159
- `navigate(route: str, page: Page, args: tuple[Any]=None) -> None` - Navigate to specific route. Specify `args` to transfer arguments to other page.
160+
- `navigate_homepage(page: Page, args: tuple[Any]=None) -> None` - Navigate to homepage (main page).
135161
- `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.
136-
- `set_route_data(self, route: str, data: Any) -> int` - Set route data (cookies-like mechanism). Returns success/fail.
137-
- `get_route_data(self, route: str) -> Any` - Get route data.
162+
- `set_route_data(route: str, data: Any) -> int` - Set route data (cookies-like mechanism). Returns success/fail.
163+
- `get_route_data(route: str) -> Any` - Get route data.
164+
- `set_homepage(homepage: str) -> None` - Set homepage (main page).
138165

139166
Using example:
140167

141168
```python
142169
from flet import app, Page, WEB_BROWSER
143170

144-
from flet_navigator import FletNavigator, Any, ROUTE_404
171+
from flet_navigator import FletNavigator ROUTE_404
145172

146173

147174
def main_page(pg: PageData) -> None:
@@ -171,6 +198,35 @@ app(target=main, view=WEB_BROWSER) # Non-Virtual Navigator recommended in web.
171198

172199
<hr>
173200

201+
<h3 align="center"><code>PageData</code></h3>
202+
203+
- `PageData` - Used for transfering data between pages.
204+
- `page: Page = None` - Current page.
205+
- `navigator: Union['FletNavigator', 'VirtualFletNavigator'] = None` - Navigator.
206+
- `arguments: Arguments = None` - Arguments sent from previous page.
207+
- `previous_page: str = None` - Previous page.
208+
- `parameters: dict[str, Any] = None` - URL parameters. (Always `None` if `VirtualFletNavigator` used).
209+
210+
<hr>
211+
212+
<h3 align="center"><code>template</code></h3>
213+
214+
```template(template_definition: TemplateDefinition, page_data: PageData) -> None```
215+
216+
Used to render template. Example:<br>
217+
218+
```python
219+
def go_to_button(pg: PageData, args: Arguments) -> None:
220+
pg.page.add(FilledButton(args[0], on_click=lambda _: pg.navigator.navigate(args[1], pg.page, args[2])))
221+
222+
def main(pg: PageData) -> None:
223+
pg.page.add(Text('Hello World!'))
224+
225+
template(go_to_button, pg, ('Go to second page.', 'second_page', None))
226+
```
227+
228+
<hr>
229+
174230
<h3 align="center"><code>define_page</code></h3>
175231

176232
```define_page(path: str, name: str=None) -> Callable[[PageData], None]```
@@ -230,4 +286,4 @@ Summary! Now you know difference between virtual and non-virtual navigator, how
230286

231287
<hr>
232288

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

0 commit comments

Comments
 (0)