Skip to content
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

Dismissible bug in v0.23.2 #3679

Closed
1 task done
BrentHuang opened this issue Jul 20, 2024 · 0 comments · Fixed by #3690
Closed
1 task done

Dismissible bug in v0.23.2 #3679

BrentHuang opened this issue Jul 20, 2024 · 0 comments · Fixed by #3690
Assignees
Labels
bug: regression A feature that worked correctly doesn't anymore

Comments

@BrentHuang
Copy link

Duplicate Check

Describe the bug

Task exception was never retrieved
future: <Task finished name='Task-104' coro=<__run_socket_server..on_event() done, defined at D:\workspace\code\account_center_h5.venv\Lib\site-packages\flet_runtime\app.py:217> exception=JSONDecodeError('Expecting value: line 1 column 1 (char 0)')>Traceback (most recent call last):
File "D:\workspace\code\account_center_h5.venv\Lib\site-packages\flet_runtime\app.py", line 219, in on_event
await conn.sessions[e.sessionID].on_event_async(
File "D:\workspace\code\account_center_h5.venv\Lib\site-packages\flet_core\page.py", line 905, in on_event_async
await handler(ce)
File "D:\workspace\code\account_center_h5.venv\Lib\site-packages\flet_core\event_handler.py", line 18, in fn
ce = self.__result_converter(e)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\workspace\code\account_center_h5.venv\Lib\site-packages\flet_core\dismissible.py", line 122, in
self._on_confirm_dismiss = EventHandler(lambda e: DismissibleDismissEvent(e))
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\workspace\code\account_center_h5.venv\Lib\site-packages\flet_core\dismissible.py", line 295, in init
d = json.loads(e.data)
^^^^^^^^^^^^^^^^^^
File "D:\program\python\Lib\json_init
.py", line 346, in loads
return _default_decoder.decode(s)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\program\python\Lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\program\python\Lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Code sample

Logs
import flet as ft


def main(page):
    page.window_height, page.window_width = 500, 400

    def close_yes_dlg(e):
        page.close_dialog()
        dlg.data.confirm_dismiss(True)

    def close_no_dlg(e):
        page.close_dialog()
        dlg.data.confirm_dismiss(False)

    dlg = ft.AlertDialog(
        modal=True,
        title=ft.Text("Please confirm"),
        content=ft.Text("Do you really want to delete this item?"),
        actions=[
            ft.TextButton("Yes", on_click=close_yes_dlg),
            ft.TextButton("No", on_click=close_no_dlg),
        ],
        actions_alignment=ft.MainAxisAlignment.CENTER,
    )

    def handle_confirm_dismiss(e: ft.DismissibleDismissEvent):
        print('on_confirm_dismiss')
        if e.direction == ft.DismissDirection.END_TO_START:  # right-to-left slide
            # 二次确认后再 dismiss
            dlg.data = e.control  # save current dismissible to dialog's data
            page.show_dialog(dlg)
        else:  # left-to-right slide
            # 不用二次确认的做法
            e.control.confirm_dismiss(True)

    def handle_dismiss(e):
        print('on_dismiss')
        lv.controls.remove(e.control)
        page.update()

    def handle_update(e: ft.DismissibleUpdateEvent):
        print(
            f"Update - direction: {e.direction}, progress: {e.progress}, reached: {e.reached}, previous_reached: {e.previous_reached}"
        )

    page.add(lv := ft.ListView(
        controls=[
            ft.Dismissible(
                content=ft.ListTile(title=ft.Text(f"Item {i}")),
                dismiss_direction=ft.DismissDirection.HORIZONTAL,
                background=ft.Container(bgcolor=ft.colors.GREEN),
                secondary_background=ft.Container(bgcolor=ft.colors.RED),
                on_dismiss=handle_dismiss,
                on_update=handle_update,
                on_confirm_dismiss=handle_confirm_dismiss,
                dismiss_thresholds={
                    ft.DismissDirection.END_TO_START: 0.2,
                    ft.DismissDirection.START_TO_END: 0.2,
                },
            ) for i in range(10)
        ],
        expand=True,
    ))


ft.app(main)

To reproduce

This bug is inevitable

Expected behavior

No response

Screenshots / Videos

Screenshots / Video demonstration

[Upload media here]

Operating System

Windows

Operating system details

window10

Flet version

0.23.2

Regression

Yes, it used to work in a previous Flet version (please specify the version in additional details)

Suggestions

No response

Logs

Logs
[Paste your logs here]

Additional details

No response

@ndonkoHenri ndonkoHenri added the bug: regression A feature that worked correctly doesn't anymore label Jul 21, 2024
@ndonkoHenri ndonkoHenri self-assigned this Jul 23, 2024
@ndonkoHenri ndonkoHenri moved this from 🆕 New to 👀 In review in Flet Development Jul 23, 2024
@github-project-automation github-project-automation bot moved this from 👀 In review to ✅ Done in Flet Development Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug: regression A feature that worked correctly doesn't anymore
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants