Skip to content
Discussion options

You must be logged in to vote

Flet is now moving towards a single-threaded async model (like in JavaScript or Flutter). Therefore, I think it’s better to adapt your code to use async, as it’s simpler and safer.

Alternatively, you could try managing threads yourself, using a more complex approach, for example:

from concurrent.futures import Future
import flet as ft

def main(page: ft.Page):
    prefs = ft.SharedPreferences()

    def set_value(e):
        page.run_task(prefs.set, store_key.value, store_value.value)
        page.show_dialog(ft.SnackBar("Value saved"))

    def get_value(e):
        future = page.run_task(prefs.get, get_key.value)
        future.add_done_callback(
            lambda f: page.run_thread(
 …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ndonkoHenri
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
help wanted Extra attention is needed
2 participants