Skip to content

Commit 8ca1cc8

Browse files
authored
Documentation.
Documentation.
1 parent f028e67 commit 8ca1cc8

File tree

1 file changed

+40
-47
lines changed

1 file changed

+40
-47
lines changed

flet-navigator-docs.md

Lines changed: 40 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<h1 align="center">FletNavigator v2.5.5 Documentation.</h1>
1+
<h1 align="center">FletNavigator v2.6.5 Documentation.</h1>
22

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

@@ -21,7 +21,7 @@ FletNavigator - Simple and fast navigator (router) for Flet (Python) that allows
2121
Installation is quite easy: ```pip install flet_navigator```
2222

2323
> [!WARNING]
24-
> FletNavigator is in active development phase + only one developers works on this project. Please, be patient and report all bugs.
24+
> FletNavigator is in active development phase + only one developer works on this project. Please, be patient and report all bugs.
2525
2626
**FletNavigator Features**:
2727
- **✨ Simple installation and very simple using.**
@@ -72,7 +72,7 @@ URL Parameters (`http://127.0.0.1:53863/second_page?id=123&etc=true`) will be re
7272

7373
Route should have latin alphabet (no cyrillic), route can have underscores and digits. Route can't have special characters, cyrillic alphabet & spaces. Wrong route will be removed from registered routes.
7474

75-
```flet_navigator::constructor:51: Warning: Wrong route name: "$my_route1У H". Allowed only digits and underscores.```
75+
```flet_navigator::constructor:302: Warning: Wrong route name: "$my_route1У H". Allowed only digits and underscores.```
7676

7777
<br>
7878

@@ -103,44 +103,41 @@ Homepage is main page, that you can set with `set_homepage`, and navigate with `
103103
- `appbars: dict[int, Control] = {}` - Dictionary of appbars for each page (ID).
104104
- `route_changed_handler: RouteChangedHandler = None` - Route changed handler.<br><br>
105105

106-
- `__init__(routes: Routes={}, route_changed_handler: Callable[[str], None]=None, navigator_animation: NavigatorAnimation=NavigatorAnimation()) -> None` - Initialize Virtual Flet Navigator.
107-
- `navigate(route: str, page: Page, args: tuple[Any]=None) -> None` - Navigate to specific route. Specify `args` to transfer arguments to other page.
108-
- `navigate_homepage(page: Page, args: tuple[Any]=None) -> None` - Navigate to homepage.
109-
- `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.
110-
- `set_route_data(self, route: str, data: Any) -> int` - Set route data (cookies-like mechanism). Returns success/fail. More <a href="https://github.com/xzripper/flet_navigator/issues/4#issuecomment-1817908000">detailed</a>.
111-
- `get_route_data(self, route: str) -> Any` - Get route data. More <a href="https://github.com/xzripper/flet_navigator/issues/4#issuecomment-1817908000">detailed</a>.
106+
- `__init__(routes: Routes={}, route_changed_handler: RouteChangedHandler=None, navigator_animation: NavigatorAnimation=NavigatorAnimation()) -> None` - Initialize Virtual Flet Navigator.
107+
- `navigate(route: str, page: Page, args: Arguments=None) -> None` - Navigate to specific route. Specify `args` to transfer arguments to other page.
108+
- `navigate_homepage(page: Page, args: Arguments=None) -> None` - Navigate to homepage.
109+
- `render(page: Page, args: Arguments=None) -> None` - Render current route. If there is no route like that throw ROUTE-404 (if specified). Should be called once.
110+
- `set_route_data(route: str, data: Any) -> int` - Set route data (cookies-like mechanism). Returns success/fail. More <a href="https://github.com/xzripper/flet_navigator/issues/4#issuecomment-1817908000">detailed</a>.
111+
- `get_route_data(route: str) -> Any` - Get route data. More <a href="https://github.com/xzripper/flet_navigator/issues/4#issuecomment-1817908000">detailed</a>.
112112
- `set_homepage(self, homepage: str) -> None` - Set homepage (main page). More <a href="https://github.com/xzripper/flet_navigator/issues/4#issuecomment-1817908000">detailed</a>.
113113

114114
Using example:
115115

116116
```python
117-
from flet import app, Page, Text
117+
from flet import app, Page, Text, FilledButton
118118

119-
from flet_navigator import VirtualFletNavigator, PageData, ROUTE_404
119+
from flet_navigator import VirtualFletNavigator, PageData, ROUTE_404, route
120120

121121

122+
@route('/')
122123
def main_page(pg: PageData) -> None:
123-
pg.page.add(Text('Main page!'))
124+
pg.add(FilledButton('Navigate to second page.', on_click=lambda _: pg.navigator.navigate('second_page', pg.page)))
124125

126+
@route('second_page')
125127
def second_page(pg: PageData) -> None:
126128
... # Second page content.
127129

128-
def route_404(pg: PageData) -> None:
129-
... # 404 Page Content.
130+
# Specify 404 page (since v2.6.5 it's optional).
131+
# @route(ROUTE_404)
132+
# def route_404(pg: PageData) -> None:
133+
# ... # 404 Page Content.
130134

135+
# Main function.
131136
def main(page: Page) -> None:
132-
# Initialize navigator.
133-
flet_navigator = VirtualFletNavigator(
134-
{
135-
'/': main_page, # Main page route.
136-
'second_page': second_page, # Second page route.
137-
ROUTE_404: route_404 # 404 page route.
138-
}, lambda route: print(f'Route changed!: {route}') # Route change handler (optional).
139-
)
140-
141-
flet_navigator.render(page) # Render current page.
137+
# Initialize navigator and render page.
138+
VirtualFletNavigator().render(page)
142139

143-
app(target=main)
140+
app(main)
144141
```
145142

146143
<hr>
@@ -157,9 +154,9 @@ app(target=main)
157154
- `appbars: dict[int, Control] = {}` - Dictionary of appbars for each page (ID).
158155
- `route_changed_handler: RouteChangedHandler = None` - Route changed handler.<br><br>
159156

160-
- `__init__(page: Page, routes: Routes={}, route_changed_handler: Callable[[str], None]=None, navigator_animation: NavigatorAnimation=NavigatorAnimation()) -> None` - Initialize Flet Navigator.
161-
- `navigate(route: str, page: Page, args: tuple[Any]=None, parameters: dict=None) -> None` - Navigate to specific route. Specify `args` to transfer arguments to other page.
162-
- `navigate_homepage(page: Page, args: tuple[Any]=None, parameters: dict=None) -> None` - Navigate to homepage (main page).
157+
- `__init__(page: Page, routes: Routes={}, route_changed_handler: RouteChangedHandler=None, navigator_animation: NavigatorAnimation=NavigatorAnimation()) -> None` - Initialize Flet Navigator.
158+
- `navigate(route: str, page: Page, args: Arguments=None, parameters: dict=None) -> None` - Navigate to specific route. Specify `args` to transfer arguments to other page. Specify `parameters` to add URL parameters.
159+
- `navigate_homepage(page: Page, args: Arguments=None, parameters: dict=None) -> None` - Navigate to homepage (main page).
163160
- `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.
164161
- `set_route_data(route: str, data: Any) -> int` - Set route data (cookies-like mechanism). Returns success/fail. More <a href="https://github.com/xzripper/flet_navigator/issues/4#issuecomment-1817908000">detailed</a>.
165162
- `get_route_data(route: str) -> Any` - Get route data. More <a href="https://github.com/xzripper/flet_navigator/issues/4#issuecomment-1817908000">detailed</a>.
@@ -168,34 +165,30 @@ app(target=main)
168165
Using example:
169166

170167
```python
171-
from flet import app, Page, Text, WEB_BROWSER
168+
from flet import app, Page, Text, FilledButton, WEB_BROWSER
172169

173-
from flet_navigator import FletNavigator ROUTE_404
170+
from flet_navigator import FletNavigator, PageData, ROUTE_404, route
174171

175172

173+
@route('/')
176174
def main_page(pg: PageData) -> None:
177-
pg.page.add(Text('Main page!'))
175+
pg.add(FilledButton('Navigate to second page.', on_click=lambda _: pg.navigator.navigate('second_page', pg.page)))
178176

177+
@route('second_page')
179178
def second_page(pg: PageData) -> None:
180179
... # Second page content.
181180

182-
def route_404(pg: PageData) -> None:
183-
... # 404 page content.
181+
# Specify 404 page (since v2.6.5 it's optional).
182+
# @route(ROUTE_404)
183+
# def route_404(pg: PageData) -> None:
184+
# ... # 404 Page Content.
184185

186+
# Main function.
185187
def main(page: Page) -> None:
186-
# Initialize navigator.
187-
flet_navigator = FletNavigator(page, # Specify page.
188-
{
189-
'/': main_page, # Main page route,
190-
'second_page': second_page, # Second page route,
191-
ROUTE_404: route_404 # 404 page route
192-
}, lambda route: print(f'Route changed!: {route}') # Route change handler (optional).
193-
)
194-
195-
# Render current page.
196-
flet_navigator.render(page)
188+
# Initialize navigator and render page.
189+
FletNavigator(page).render(page)
197190

198-
app(target=main, view=WEB_BROWSER) # Non-Virtual Navigator recommended in web.
191+
app(main, view=WEB_BROWSER)
199192
```
200193

201194
<hr>
@@ -259,7 +252,7 @@ def main(page: Page) -> None:
259252
<h3 align="center"><code>route</code></h3>
260253

261254
`route` added in `V2.4.5` and used to specify routes using decorator. Example:
262-
```
255+
```python
263256
@route('/')
264257
def main_page(pg: PageData) -> None:
265258
...
@@ -347,4 +340,4 @@ Summary! Now you know difference between virtual and non-virtual navigator, how
347340

348341
<hr>
349342

350-
<p align="center"><b><i>FletNavigator V2.5.5</i></b></p>
343+
<p align="center"><b><i>FletNavigator V2.6.5</i></b></p>

0 commit comments

Comments
 (0)