-
Notifications
You must be signed in to change notification settings - Fork 614
Add Flutter Secure Storage extension
#6001
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
Changes from all commits
e605a7a
46e828c
70a55b4
15b4585
3c2a59e
e187eca
bb7c836
3209d05
d9162a8
8db0ef2
33ce688
28094e3
6be0b0e
1d2cd4d
06d75f6
4c684e6
cd43ad6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -371,35 +371,39 @@ class Control extends ChangeNotifier { | |
| var node = getPatchTarget(op[1]); | ||
| var index = op[2]; | ||
| var value = op[3]; | ||
| if (node.obj is! List) { | ||
| throw Exception("Add operation can be applied to lists only: $op"); | ||
| } | ||
| node.obj | ||
| .insert(index, _transformIfControl(value, node.control, backend)); | ||
| if (shouldNotify) { | ||
| node.control.notify(); | ||
| if (node.obj is Map) { | ||
| node.obj[index] = _transformIfControl(value, node.control, backend); | ||
| } else if (node.obj is List) { | ||
| node.obj.insert(index, _transformIfControl(value, node.control, backend)); | ||
| } else { | ||
| throw Exception("Add operation can be applied to lists or maps: $op"); | ||
| } | ||
| if (shouldNotify) node.control.notify(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What did the changes in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was getting an exception from line 378 when calling the These changes make it possible to work with a map at runtime, which is what FlutterSecureStorage actually uses. |
||
| } else if (opType == OperationType.remove) { | ||
| // REMOVE | ||
| var node = getPatchTarget(op[1]); | ||
| var index = op[2]; | ||
| if (node.obj is! List) { | ||
| throw Exception("Remove operation can be applied to lists only: $op"); | ||
| } | ||
| node.obj.removeAt(index); | ||
| if (shouldNotify) { | ||
| node.control.notify(); | ||
| if (node.obj is List) { | ||
| node.obj.removeAt(index); | ||
| } else if (node.obj is Map) { | ||
| node.obj.remove(index); | ||
| } else { | ||
| throw Exception("Remove operation can be applied to lists or maps: $op"); | ||
| } | ||
| if (shouldNotify) node.control.notify(); | ||
| } else if (opType == OperationType.move) { | ||
| // MOVE | ||
| var fromNode = getPatchTarget(op[1]); | ||
| var fromIndex = op[2]; | ||
| var toNode = getPatchTarget(op[3]); | ||
| var toIndex = op[4]; | ||
| if (fromNode.obj is! List || toNode.obj is! List) { | ||
| throw Exception("Move operation can be applied to lists only: $op"); | ||
| if (fromNode.obj is List && toNode.obj is List) { | ||
| toNode.obj.insert(toIndex, fromNode.obj.removeAt(fromIndex)); | ||
| } else if (fromNode.obj is Map && toNode.obj is Map) { | ||
| toNode.obj[toIndex] = fromNode.obj.remove(fromIndex); | ||
| } else { | ||
| throw Exception("Move operation can only be applied to lists or maps: $op"); | ||
7576457 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| toNode.obj.insert(toIndex, fromNode.obj.removeAt(fromIndex)); | ||
| if (shouldNotify) { | ||
| if (fromNode.control.id != toNode.control.id) { | ||
| fromNode.control.notify(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| import base64 | ||
| import os | ||
|
|
||
| import flet as ft | ||
| import flet_secure_storage as fss | ||
|
|
||
|
|
||
| def main(page: ft.Page): | ||
| page.vertical_alignment = ft.MainAxisAlignment.CENTER | ||
| page.horizontal_alignment = ft.CrossAxisAlignment.CENTER | ||
| storage = fss.SecureStorage( | ||
| web_options=fss.WebOptions( | ||
| db_name="customstorage", | ||
| public_key="publickey", | ||
| wrap_key=base64.urlsafe_b64encode(os.urandom(32)).decode(), | ||
| wrap_key_iv=base64.urlsafe_b64encode(os.urandom(16)).decode(), | ||
| ), | ||
| android_options=fss.AndroidOptions( | ||
| reset_on_error=True, | ||
| migrate_on_algorithm_change=True, | ||
| enforce_biometrics=True, | ||
| key_cipher_algorithm=fss.KeyCipherAlgorithm.AES_GCM_NO_PADDING, | ||
| storage_cipher_algorithm=fss.StorageCipherAlgorithm.AES_GCM_NO_PADDING, | ||
| ), | ||
| ) | ||
|
|
||
| key = ft.TextField(label="Key", value="example_key") | ||
| value = ft.TextField(label="Value", value="secret_value") | ||
| result = ft.Text(theme_style=ft.TextThemeStyle.TITLE_LARGE) | ||
|
|
||
| async def set_value(e): | ||
| await storage.set(key.value, value.value) | ||
| result.value = "Value saved" | ||
| page.update() | ||
|
|
||
| async def get_value(e): | ||
| result.value = await storage.get(key.value) | ||
| page.update() | ||
|
|
||
| async def remove_value(e): | ||
| await storage.remove(key.value) | ||
| result.value = "Value removed" | ||
| page.update() | ||
|
|
||
| async def clear_storage(e): | ||
| await storage.clear() | ||
| result.value = "Storage cleared" | ||
| page.update() | ||
|
|
||
| async def contains_key(e): | ||
| exists = await storage.contains_key(key.value) | ||
| result.value = f"Key exists: {exists}" | ||
| page.update() | ||
|
|
||
| async def get_availability(e): | ||
| is_availability = await storage.get_availability() | ||
| page.show_dialog( | ||
| ft.SnackBar( | ||
| content=ft.Text( | ||
| value=f"Protected data available: {is_availability}" | ||
| if is_availability | ||
| else "Protected data available: None" | ||
| ) | ||
| ) | ||
| ) | ||
7576457 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| page.update() | ||
|
|
||
| page.add( | ||
| ft.Column( | ||
| alignment=ft.MainAxisAlignment.CENTER, | ||
| horizontal_alignment=ft.CrossAxisAlignment.CENTER, | ||
| spacing=10, | ||
| controls=[ | ||
| result, | ||
| key, | ||
| value, | ||
| ft.Row( | ||
| width=300, | ||
| wrap=True, | ||
| controls=[ | ||
| ft.Button("Set", on_click=set_value), | ||
| ft.Button("Get", on_click=get_value), | ||
| ft.Button("Contains key", on_click=contains_key), | ||
| ft.Button("Remove", on_click=remove_value), | ||
| ft.Button("Clear", on_click=clear_storage), | ||
| ft.Button("Check Data Availability", on_click=get_availability), | ||
| ], | ||
| ), | ||
| ], | ||
| ), | ||
| ) | ||
|
|
||
|
|
||
| ft.run(main) | ||
Uh oh!
There was an error while loading. Please reload this page.