Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
CognitoSecureStorage for Amazon Cognito Identity Dart ( https://pub.dartlang.org/packages/amazon_cognito_identity_dart )
import 'package:amazon_cognito_identity_dart/cognito.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'dart:convert';
class CognitoSecureStorage extends CognitoStorage {
FlutterSecureStorage _securePrefs = new FlutterSecureStorage();
CognitoSecureStorage();
@override
Future getItem(String key) async {
String item;
try {
item = json.decode(await _securePrefs.read(key: key));
} catch (e) {
return null;
}
return item;
}
@override
Future setItem(String key, value) async {
_securePrefs.write(key: key, value: json.encode(value));
return getItem(key);
}
@override
Future removeItem(String key) async {
final item = getItem(key);
if (item != null) {
_securePrefs.delete(key: key);
return item;
}
return null;
}
@override
Future<void> clear() async {
_securePrefs.deleteAll();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.