Skip to content

Instantly share code, notes, and snippets.

@Vortexmind
Created April 8, 2019 22:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Vortexmind/c3551cbe41493ab735b403669b962ed1 to your computer and use it in GitHub Desktop.
Save Vortexmind/c3551cbe41493ab735b403669b962ed1 to your computer and use it in GitHub Desktop.
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