Add initial project structure and configuration files for iOS and Android
This commit is contained in:
34
lib/security/secure_storage.dart
Normal file
34
lib/security/secure_storage.dart
Normal file
@@ -0,0 +1,34 @@
|
||||
import 'dart:convert';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
|
||||
class SecureStorage {
|
||||
final FlutterSecureStorage _storage;
|
||||
|
||||
SecureStorage(): _storage = const FlutterSecureStorage();
|
||||
|
||||
Future<void> write(String key, dynamic value) async {
|
||||
final stringValue = value is String
|
||||
? value
|
||||
: json.encode(value);
|
||||
await _storage.write(key: key, value: stringValue);
|
||||
}
|
||||
|
||||
Future<dynamic> read(String key) async {
|
||||
final value = await _storage.read(key: key);
|
||||
if (value == null) return null;
|
||||
|
||||
try {
|
||||
return json.decode(value);
|
||||
} catch (_) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> delete(String key) async {
|
||||
await _storage.delete(key: key);
|
||||
}
|
||||
|
||||
Future<void> deleteAll() async {
|
||||
await _storage.deleteAll();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user