Skip to main content

Navigator for Flet.

Project description

Simple and fast navigator (router) for Flet (Python) that allows you to create multi-page applications in one page!

Using Example:

from flet import app, Page, Text, FilledButton, TextThemeStyle

from flet_navigator import FletNavigator, Any, ROUTE_404

from random import randint


# Main page content.
# page - Current page,
# navigator - With this you can navigate to other pages,
# args - Arguments sent from other page.
# Using these all typehints is optional.
def main_page(page: Page, navigator: FletNavigator, args: tuple[Any]) -> None:
   page.add(Text('Main Page!', style=TextThemeStyle.DISPLAY_MEDIUM))

   if args:
      page.add(Text(f'Message from {args[0]}: {args[1]}.'))

   page.add(
      FilledButton(
            'Navigate to second page!',

            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!
      )
   )

   page.add(
      FilledButton(
            'Navigate to really_non_existent_page!',

            on_click=lambda _: navigator.navigate('really_non_existent_page', page) # Navigate to non-existent page. Will result route_404.
      )
   )

# Second page content.
def second_page(page: Page, navigator: FletNavigator, args: tuple[Any]) -> None:
   page.add(Text('Second Page!', style=TextThemeStyle.DISPLAY_SMALL))

   page.add(Text(f'Message from {args[0]}: {args[1]}'))

   page.add(
      FilledButton(
            'Navigate to main page!',

            on_click=lambda _: navigator.navigate('/', page, ('second page', randint(1, 100))) # Navigate to main page, and send random number as arguments!
      )
   )

# 404 page content.
def route_404(page: Page, navigator: FletNavigator, args: tuple[Any]) -> None:
   page.add(Text('How did you get here? There is no page like this registered in routes...'))

   page.add(
      FilledButton(
            'Navigate to the main page until it is too late...',

            on_click=lambda _: navigator.navigate('/', page) # Navigate to main page.
      )
   )

# Main function. Being used only for routing.
def main(page: Page) -> None:
   # Initialize navigator.
   flet_navigator = FletNavigator(
      {
            '/': main_page, # Specify main page,
            'second_page': second_page, # Specify second page,
            ROUTE_404: route_404 # Specify 404 page (optional).
      }, lambda route: print(f'Route changed!: {route}') # On route changed handler (optional).
   )

   flet_navigator.render(page) # Render main page.

app(target=main) # Run main fuction.

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.

This example will be updated in next releases to keep everything up to date.


FletNavigator V1.0.1.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flet_navigator-1.0.1.tar.gz (3.7 kB view details)

Uploaded Source

File details

Details for the file flet_navigator-1.0.1.tar.gz.

File metadata

  • Download URL: flet_navigator-1.0.1.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.9

File hashes

Hashes for flet_navigator-1.0.1.tar.gz
Algorithm Hash digest
SHA256 3dff963e78f0cbdfda9491e7908af3a56b53cd1ff54e629ce0a404349e8cc6f4
MD5 79f6aacf4d7f33d4e531767361fac8e3
BLAKE2b-256 7362d187ca34e27932a86f28ba2d196f3eab3565543bdf8817fadbbb252fc3e2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page