import flet as ft
class Search(ft.Container):
def __init__(self):
super().__init__()
def close_f(e):
self.close_bt.visible=False
self.tf.value=""
self.update()
self.close_bt=ft.IconButton(icon=ft.Icons.CLOSE,icon_size=15,
on_click=close_f,hover_color=ft.Colors.TRANSPARENT,)
self.tf=ft.TextField(prefix_icon=ft.IconButton(ft.Icons.SEARCH,hover_color=ft.Colors.TRANSPARENT,icon_size=15,),
suffix_icon=self.close_bt,
hint_text="搜索",
text_size=12,
text_style=ft.TextStyle(height=0.5),
filled=False,
border_width=1,
border_color=ft.Colors.TRANSPARENT,
on_blur=self.search_blur,
on_focus=self.search_focus,
height=30,
cursor_height=15,
cursor_width=1,
cursor_color=ft.Colors.BLUE,
focused_border_color=ft.Colors.BLUE,
)
self.add_bt = ft.IconButton(icon=ft.Icons.ADD,width=30,height=30,icon_size=15,
style=ft.ButtonStyle(
bgcolor={ft.ControlState.FOCUSED: ft.Colors.PINK_200, "": ft.Colors.GREY_200},
shape={
ft.ControlState.DEFAULT:ft.RoundedRectangleBorder(radius=2),
}
),
on_click= lambda e : print(e)
)
def search_blur(self,e):
self.close_bt.visible=False
e.control.hint_text="搜索",
self.update()
print(e)
def search_focus(self,e):
self.close_bt.visible=True
e.control.hint_text="",
self.update()
print(e)
def build(self):
self.content=ft.Row(controls=[
ft.Container(bgcolor=ft.Colors.GREY_200,
border_radius=2,
content=self.tf,
expand=True
),
self.add_bt,
])
class ChatList(ft.Container):
def __init__(self):
super().__init__()
self.padding=ft.padding.only(top=20,left=10,right=10,bottom=10)
self.border_radius=1
self.width=300
def build(self):
self.content=ft.Column(controls=[
Search(),
ft.Stack(expand=True,controls=[
ft.ListView(
controls=[
ft.ListTile(
height=70,
hover_color=ft.Colors.GREY_100,
leading=ft.Icon(ft.Icons.SNOOZE,size=50),
title=ft.Text(
"Two-line with leading and trailing controls",
overflow=ft.TextOverflow.ELLIPSIS
),
subtitle=ft.Text("Here is a second title.",overflow=ft.TextOverflow.ELLIPSIS),
on_click= lambda e : print(e),
) for i in range(300)
]
) ,
]),
])
class ChatPage(ft.Row):
def __init__(self,page: ft.Page):
super().__init__(expand=True)
chat_list =ChatList()
def move_vertical_divider(e: ft.DragUpdateEvent):
if (e.local_delta.x > 0 and chat_list.width < 360) or (e.local_delta.x < 0 and chat_list.width > 100):
chat_list.width += e.local_delta.x
chat_list.update()
def show_draggable_cursor(e: ft.HoverEvent):
e.control.mouse_cursor = ft.MouseCursor.RESIZE_LEFT_RIGHT
e.control.update()
cl=ChatList()
self.controls=[chat_list,ft.GestureDetector(
content=ft.VerticalDivider(),
drag_interval=10,
on_pan_update=move_vertical_divider,
on_hover=show_draggable_cursor,
),ft.Container(bgcolor=ft.Colors.GREEN,expand=True)]
page.theme= ft.Theme(
)
page.bgcolor=ft.Colors.WHITE
page.add(self)
def will_unmount(self):
print("ChatPage will unmount")
return super().will_unmount()
def did_mount(self):
print("ChatPage did mount")
return super().did_mount()
if __name__ == '__main__':
ft.run(ChatPage)
Duplicate Check
Describe the bug
QQ202598-214437.mp4
Code sample
Code
To reproduce
s
Expected behavior
No response
Screenshots / Videos
Captures
[Upload media here]
Operating System
Windows
Operating system details
11
Flet version
0.28.3 or V1
Regression
No, it isn't
Suggestions
No response
Logs
Logs
[Paste your logs here]Additional details
No response