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

Fix null check error and improve error handling in web implementation #782

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions flutter_secure_storage_web/lib/flutter_secure_storage_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,26 @@ class FlutterSecureStorageWeb extends FlutterSecureStoragePlatform {
}
}

/// Encrypts and saves the [key] with the given [value].
/// Reads and decrypts the value for the given [key].
///
/// If the key was already in the storage, its associated value is changed.
/// If the value is null, deletes associated value for the given [key].
/// Returns null if the key does not exist or if decryption fails.
@override
Future<String?> read({
required String key,
required Map<String, String> options,
}) async {
final value = web.window.localStorage["${options[_publicKey]!}.$key"];

return _decryptValue(value, options);
if (value == null) {
return null;
}

try {
return await _decryptValue(value, options);
} catch (e) {
print("Error decrypting value: $e");
return null;
}
}

/// Decrypts and returns all keys with associated values.
Expand Down Expand Up @@ -258,13 +266,6 @@ class FlutterSecureStorageWeb extends FlutterSecureStoragePlatform {

return plainText;
}

// @override
// Future<bool> isCupertinoProtectedDataAvailable() => Future.value(false);
//
// @override
// Stream<bool> get onCupertinoProtectedDataAvailabilityChanged =>
// Stream.empty();
}

extension on List<String> {
Expand Down