Replies: 1 comment
-
|
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 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(
lambda: update_value(f)
)
)
def update_value(f: Future):
try:
get_inp.value = f.result()
page.update()
except Exception:
page.show_dialog(ft.SnackBar("Error"))
page.add(
ft.Column(
[
ft.Row(
[
store_key := ft.TextField(label="Key"),
store_value := ft.TextField(label="Value"),
ft.Button("Set", on_click=set_value),
]
),
ft.Row(
[
get_key := ft.TextField(label="Key"),
get_inp := ft.TextField(label="Value"),
ft.Button("Get", on_click=get_value),
]
),
]
)
)
ft.run(main)I don’t think you really need to go this route. Managing threads and the associated logic adds complexity as your project grows. Besides being harder to maintain, it can also negatively impact performance https://flet.dev/blog/introducing-flet-1-0-alpha/#single-threaded-async-ui-model |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Question
Hello i try to migrate my apps from flet 0.28.3 to 0.80.1.
In the past i used simply e.g
page.client_storage.get("xyz")in my non async apps.i found the new docs with a new basic example but all that covers only async apps.
(https://docs.flet.dev/services/sharedpreferences/?h=sharedpreferences)
How can i deal with it in non async apps ?
Any help would be great, thanks in advanced.
Code sample
Error message
No response
------------------------------------------------------
Beta Was this translation helpful? Give feedback.
All reactions