-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issues with pages being read twice #14
Comments
It is a bug that occurs in non-async functions, thanks for reporting it. If another bug is found, please report it so we can add the fix along with it. |
It works fine. Thank you |
not work, i use
|
Check this please:
If you don't find a solution, create a new Issue, with a more detailed example of the errors it presents, please. |
This is a way to use the import flet as ft
import flet_easy as fs
app = fs.FletEasy(route_init="/home")
""" Generate configuration of the app through the page property, for greater order in the code. """
@app.config
def config(data: fs.Datasy):
page = data.page
page.title = "test app"
page.window_min_width = 600
page.window_min_height = 800
theme = ft.Theme(font_family="Microsoft Yahei")
theme.page_transitions.windows = ft.PageTransitionTheme.NONE
page.theme = theme
""" Configure through fs.Viewsy to be able to reuse in ft.View on each page. """
@app.view
def view(data: fs.Datasy):
page = data.page
def modify_theme():
if page.theme_mode == ft.ThemeMode.DARK:
page.theme_mode = ft.ThemeMode.LIGHT
else:
page.theme_mode = ft.ThemeMode.DARK
def theme(e):
if page.theme_mode == ft.ThemeMode.SYSTEM:
modify_theme()
modify_theme()
page.update()
nav = ft.NavigationBar(
destinations=[
ft.NavigationDestination(icon=ft.icons.EXPLORE, label="Explore"),
ft.NavigationDestination(icon=ft.icons.COMMUTE, label="Commute"),
ft.NavigationDestination(
icon=ft.icons.BOOKMARK_BORDER,
selected_icon=ft.icons.BOOKMARK,
label="Explore",
),
]
)
app_bar = ft.AppBar(
title=ft.Image(src="baolaailogo.png", height=50),
center_title=False,
leading_width=40,
bgcolor=ft.colors.SURFACE_VARIANT,
actions=[
ft.IconButton(ft.icons.WB_SUNNY_OUTLINED, on_click=theme),
ft.PopupMenuButton(
items=[
ft.PopupMenuItem(text="🔥 Home", on_click=data.go(data.route_init)),
]
),
ft.IconButton(
ft.icons.TIPS_AND_UPDATES_OUTLINED,
tooltip="去更新或者提出想法",
url="https://daxexs.github.io/flet-easy/0.2/Customized-app/Control-view-configuration/",
),
],
)
controls = [
ft.Row(
controls=[
ft.NavigationRail(
selected_index=0,
label_type=ft.NavigationRailLabelType.ALL,
# extended=True,
min_width=100,
min_extended_width=400,
leading=ft.FloatingActionButton(icon=ft.icons.CREATE, text="Add"),
group_alignment=-0.9,
destinations=[
ft.NavigationRailDestination(
icon=ft.icons.FAVORITE_BORDER,
selected_icon=ft.icons.FAVORITE,
label="First",
),
ft.NavigationRailDestination(
icon_content=ft.Icon(ft.icons.BOOKMARK_BORDER),
selected_icon_content=ft.Icon(ft.icons.BOOKMARK),
label="Second",
),
ft.NavigationRailDestination(
icon=ft.icons.SETTINGS_OUTLINED,
selected_icon_content=ft.Icon(ft.icons.SETTINGS),
label_content=ft.Text("Settings"),
),
],
on_change=lambda e: print(
"Selected destination:", e.control.selected_index
),
),
ft.VerticalDivider(width=1),
],
vertical_alignment=ft.CrossAxisAlignment.START,
alignment=ft.MainAxisAlignment.START,
expand=True,
)
]
""" We return ft.Viewsy """
return fs.Viewsy(
navigation_bar=nav,
appbar=app_bar,
controls=controls,
auto_scroll=ft.ScrollMode.AUTO,
vertical_alignment=ft.MainAxisAlignment.START,
horizontal_alignment=ft.CrossAxisAlignment.START,
)
""" Page in which we will reuse fs.Viewsy, we can access all the attributes that we have previously configured. """
@app.page(route="/home")
def login_page(data: fs.Datasy):
view = data.view
""" Add controls to view, since it is created. """
view.controls[0].controls.append(ft.Text("Hello, world!"))
return ft.View(
controls=view.controls,
navigation_bar=view.navigation_bar,
appbar=view.appbar,
vertical_alignment=view.vertical_alignment,
horizontal_alignment=view.horizontal_alignment,
)
app.run() |
code :
result :
requirements:
os
When I loaded the page, I noticed that the log was called twice,
so I checked with my test code. Is this a bug?
The text was updated successfully, but these errors were encountered: