feat: implement adaptive layout and sync navigation state
This commit is contained in:
+21
-7
@@ -1,17 +1,31 @@
|
||||
import flet as ft
|
||||
|
||||
from app.widgets.adaptive_menu import adaptive_menu
|
||||
from app.widgets.adaptive_menu import adaptive_menu, get_selected_index_from_route
|
||||
|
||||
MOBILE_BREAKPOINT = 600
|
||||
|
||||
def get_layout_mode(page: ft.Page):
|
||||
width = page.width if page.width and page.width > 0 else 1024
|
||||
return "mobile" if width < MOBILE_BREAKPOINT else "desktop"
|
||||
|
||||
def main_layout(page: ft.Page, content_container: ft.Container):
|
||||
print(">>> ENTER main_layout")
|
||||
menu = adaptive_menu(page)
|
||||
|
||||
# ตรวจสอบโหมด (ป้องกันหน้าจอขาวจาก width=0)
|
||||
width = page.width if page.width > 0 else 1024 # default ไว้ที่ desktop ก่อนถ้ายังไม่รู้ width
|
||||
is_mobile = width < 600
|
||||
print(f">>> Device mode: {'MOBILE' if is_mobile else 'DESKTOP'} (Width: {page.width})")
|
||||
mode = get_layout_mode(page)
|
||||
|
||||
if is_mobile:
|
||||
# เก็บ mode instance ไว้ที่ page
|
||||
page._layout_mode = mode
|
||||
|
||||
selected_index = get_selected_index_from_route(page.route)
|
||||
|
||||
menu = adaptive_menu(page, selected_index)
|
||||
|
||||
# เก็บ menu instance ไว้ที่ page
|
||||
page._menu_control = menu
|
||||
|
||||
print(f">>> Device mode: {mode}")
|
||||
|
||||
if mode == "mobile":
|
||||
return ft.Column(
|
||||
controls=[
|
||||
content_container,
|
||||
|
||||
Reference in New Issue
Block a user