123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- import 'dart:convert';
- import 'package:flutter_secure_storage/flutter_secure_storage.dart';
- class SecureStorageUtil {
-
- static final SecureStorageUtil _singleton = SecureStorageUtil._internal();
-
- SecureStorageUtil._internal();
-
- factory SecureStorageUtil() => _singleton;
-
- final _storage = const FlutterSecureStorage();
-
- Future<void> setString(String key, String value) async {
- await _storage.write(key: key, value: value);
- }
-
- Future<String?> getString(String key) async {
- return await _storage.read(key: key);
- }
-
- Future<void> setJsonList(String key, List<Map<String, dynamic>> jsonList) async {
- final jsonString = jsonEncode(jsonList);
- await _storage.write(key: key, value: jsonString);
- }
-
- Future<List<Map<String, dynamic>>?> getJsonList(String key) async {
- final jsonString = await _storage.read(key: key);
- return jsonString != null ? List<Map<String, dynamic>>.from(jsonDecode(jsonString)) : null;
- }
-
- Future<void> delete(String key) async {
- await _storage.delete(key: key);
- }
-
- Future<void> deleteAll() async {
- await _storage.deleteAll();
- }
- }
|