flet icon indicating copy to clipboard operation
flet copied to clipboard

Datatable freezes. flet 0.22

Open Mars687p opened this issue 10 months ago • 3 comments

Description When migrating from flet 0.18 to flet 0.22, my Datatable started to slow down my application. An example that causes a hang. Maybe I'm doing something wrong? Although everything worked well in version 0.18.

Code example to reproduce the issue:

     class PickBottlingView:
            def __init__(self, page):
                self.page: ft.Page = page
    
    
        async def pick_bottling(self):         
            async def input_task(e: ft.ControlEvent):
                async def close_dialog(e: ft.ControlEvent):
                    dg.open = False
                    self.page.update()
    
                dg = ft.AlertDialog(title=ft.Text('Very slow opening'), 
                            actions=[ft.TextButton('Okay', on_click=close_dialog)])
                self.page.dialog = dg
                dg.open = True
                self.page.update()
                return
    
    
            
            # Only one line can be active
            self.active_row: ft.DataRow = None
            async def pick_row_bt(e: ft.ControlEvent):
                if self.active_row == None:
                    self.active_row = e.control
                else:
                    self.active_row.selected = False
                    self.active_row = e.control
                
                # is not active row? If yes, then do active
                if not e.control.selected: 
                    e.control.selected = True
                self.page.update()
            
    
    
            lst_task = ft.DataTable(
                                  columns=[ 
                                    ft.DataColumn(ft.Container(
                                              ft.Text('barcode'), expand=True, alignment=ft.alignment.center,), 
                                                on_sort=lambda x: print(x.data)),
                                    ft.DataColumn(ft.Container(
                                              ft.Text('Name'), expand=True, 
                                              alignment=ft.alignment.center,), on_sort=lambda x: print(x.data)),
                                    ft.DataColumn(ft.Container(
                                               ft.Text('Volume'), expand=True, alignment=ft.alignment.center,)),
                                    ft.DataColumn(ft.Container(
                                                ft.Text('Quantity'), expand=True, alignment=ft.alignment.center,)),
                                    ft.DataColumn(ft.Container(
                                                ft.Text('Create date'), expand=True, alignment=ft.alignment.center,)),
                                    ft.DataColumn(ft.Container(
                                                ft.Text('Batch'), expand=True, alignment=ft.alignment.center,)),
                                    ft.DataColumn(ft.Container(
                                                ft.Text('Count in box'), expand=True, alignment=ft.alignment.center,))],
                                      rows=[],
                                      heading_row_color=ft.colors.BLACK12,
                                      heading_row_height=50, 
                                      horizontal_lines=ft.border.BorderSide(1, "black"),
                                      show_bottom_border=True,
                                      expand=True,
                                      bgcolor=ft.colors.WHITE, )
    
    
            for item in range(350):
                if not item % 2:
                    color_row = {ft.MaterialState.DEFAULT: ft.colors.with_opacity(0.7, ft.colors.YELLOW_50),
                                ft.MaterialState.HOVERED: ft.colors.BLUE_100,
                                ft.MaterialState.PRESSED: ft.colors.BLUE_400,
                                ft.MaterialState.SELECTED: ft.colors.BLUE_300}
                else: 
                    color_row = {ft.MaterialState.DEFAULT: ft.colors.WHITE70,
                                ft.MaterialState.HOVERED: ft.colors.BLUE_100,
                                ft.MaterialState.PRESSED: ft.colors.BLUE_400,
                                ft.MaterialState.SELECTED: ft.colors.BLUE_300}
    
                lst_task.rows.append(ft.DataRow(cells=
                                            [ft.DataCell(ft.Text(item)),
                                            ft.DataCell(ft.Text(item)),
                                            ft.DataCell(ft.Text(item)),
                                            ft.DataCell(ft.Text(item)),
                                            ft.DataCell(ft.Text(item)),
                                            ft.DataCell(ft.Text(item)),
                                            ft.DataCell(ft.Text(item)),
                                            ],                                      
                                        data=item, 
                                        on_select_changed=pick_row_bt,
                                        color=color_row)
                                    )
            but_input = ft.ElevatedButton(content=ft.Container(ft.Text('Выбрать задание', size=24)), 
                                            on_click=input_task)
            self.page.add(ft.Column([
                    ft.Text('TASKS', size=28, weight=ft.FontWeight.BOLD),
                    ft.Container(
                        ft.ListView([lst_task]), 
                        height=700, bgcolor=ft.colors.WHITE,
                        border=ft.border.all(2, "black"),
                        ),
                    ft.Row([
                        but_input
                        ], alignment=ft.MainAxisAlignment.END, 
                    )], 
                    alignment=ft.MainAxisAlignment.CENTER,
                    horizontal_alignment=ft.CrossAxisAlignment.CENTER,
                    scroll=ft.ScrollMode.AUTO
                )
            )
        
    
    async def main(page: ft.Page):
        page.window_min_height = 1280
        page.window_min_width = 1280
        page.theme = ft.Theme(color_scheme_seed='white')
        page.theme_mode = 'light'
        page.vertical_alignment = ft.MainAxisAlignment.CENTER
        page.horizontal_alignment = ft.MainAxisAlignment.CENTER
        page.bgcolor = ft.colors.LIGHT_GREEN_100
        page.window_maximized = True
        page.window_maximizable = True
        app = PickBottlingView(page)
        await app.pick_bottling()
    
        
    
    if __name__ == '__main__':
        ft.app(target=main) `

Describe the results you expected: The response to any action has become long. Animations have become jerky

Flet version (pip show flet):

Name: flet
Version: 0.22.0
Summary: Flet for Python - easily build interactive multi-platform apps in Python
Home-page:
Author: Appveyor Systems Inc.
Author-email: [email protected]
License: Apache-2.0
Location: E:\progs\flet datatable\env\Lib\site-packages
Requires: cookiecutter, fastapi, flet-runtime, packaging, qrcode, uvicorn, watchdog
Required-by:

Give your requirements.txt file (don't pip freeze, instead give direct packages):

flet==0.22.0

Operating system: Windows 10 21H2

Mars687p avatar Apr 22 '24 13:04 Mars687p

Could you please use the template to submit the issue and provide a complete runnable repro?

FeodorFitsner avatar Apr 28 '24 17:04 FeodorFitsner

I edited the message. The code is working

Mars687p avatar May 02 '24 07:05 Mars687p

I ran the code with the latest Flet version and it works as expected. Could you please better explain your issue, and if possible provide a screen record?

ndonkoHenri avatar Jun 21 '24 01:06 ndonkoHenri