until now, flet does not support multi pages.
With this tool, you can start new pages on the same script without the need of creating new app class or new cmd process etc...
pip install flet-multi-page --upgrade
Its very simple, you just need to import the package and import the class subPage.
This is an example code:
from flet_multi_page import subPage
import flet
def main (page:flet.Page):
def start_new_page (e):
p = subPage(controls=[flet.Text("Hello from the new page!!")], page_props={"bgcolor":"blue"})
p.start()
page.add(flet.ElevatedButton("start new page", on_click=start_new_page))
page.update()
if __name__ == "__main__": #? This is so important, there will be errors without it.
flet.app(target=main)Or if you want a second target function for the page you can just add target argument like this:
from flet_multi_page import subPage
import flet
import random
def second_target (page:flet.Page): #? This is the target function of the second page.
colors = ["blue", "pink", "black", "red", "green"]
page.bgcolor = random.choice(colors)
page.add(flet.Text("Hello new page!", color="white"))
page.update()
def main (page:flet.Page):
def start_new_page (e):
p = subPage(target=second_target) #! This is the "subPage" class.
p.start() #! This will run and start the second page.
page.add(flet.ElevatedButton("start new page", on_click=start_new_page))
page.update()
if __name__ == "__main__": #? This is so important, there will be errors without it.
flet.app(target=main)controlsargument (optional): You can add the controls you need directly to the new page.page_propsargument (optional): You can add the page properties you want as dict.targetargument (optional): You can set a target function to call for the new page, and getpageclass as an argument.viewargument (optional): The default isFLET_APPwhich is a desktop app view, you can change it toflet.WEB_BROWSERorweb_browserto make the page open in a web_browser.