An encrypted storage option for Flet that stores data securely, based on the platform, it is designed to be similiar to the SharedPreferences (previously ClientStorage) class in Flet v1.
It utilizes the flutter_secure_storage Flutter package
| Platform | Supported |
|---|---|
| Windows | ✅ |
| Android | ✅ |
| Web | ✅ |
| Linux | ✅ |
| macOS | 🚧 |
| iOS | 🚧 |
ℹ️ Note: Currently unable to verify on macOS or iOS.
| Version | Supported |
|---|---|
| >= 0.80.0 | ✅ |
| < 0.28.3 | ❌ |
To install the flet-secure-storage package and add it to your project dependencies:
-
Using
uv:uv add flet-secure-storage
-
Using
pip:pip install flet-secure-storage
After this, you will have to manually add this package to your
requirements.txtorpyproject.toml.[project] dependencies = [ "flet-secure-storage", "flet>=0.80.0", ]
-
Add secure_storage to the page services.
import flet as ft from flet_secure_storage import SecureStorage async def main(page: ft.Page): secure_storage = SecureStorage() # Create an instance of secure_storage page.services.append(secure_storage) # Add secure_storage to services # Code ft.run(main)
-
Add secure_storage to the page services.
import flet as ft from flet_secure_storage import SecureStorage, AndroidOptions async def main(page: ft.Page): secure_storage = SecureStorage( prefix="com.example", # `.` is added automatically between prefix and key prefix_separator=".", # Default a_options=AndroidOptions( shared_preferences_name="my_project", preferences_key_prefix="com.project" ) # Add other platform options ) # Create an instance of secure_storage page.services.append(secure_storage) # Add secure_storage to services # Code ft.run(main)
-
set - Set a value by key in storage
await secure_storage.set("key", "value") return bool
-
get - Retrieve a value from storage by it's key
value = await secure_storage.get("key") return value: str
-
contains_key - Check if a key exists in storage by it's key
await secure_storage.contains_key("key"): return bool
-
remove - Removes the key, value pair from storage
await secure_storage.remove("key") return bool
-
get_keys - Gets all keys that startwith the entered key. Returns all keys if blank.
values = await secure_storage.get_keys("key": str = "") # No entry or an entry of '' will produce keys starting with the `prefix=` option. return values: list[str] # input key = "key" # return ['key1:value1', 'key2:value2']
-
clear - Clears all keys from storage.
await secure_storage.remove("key")
To get a more through explanation, check out the documentation.