This commit is contained in:
Hamza-Ayed
2025-01-04 21:58:13 +03:00
parent fdd203aa7c
commit 63681f104c
9 changed files with 287 additions and 46 deletions

View File

@@ -1,5 +1,11 @@
import 'dart:convert';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import '../../constant/links.dart';
import '../../main.dart';
import 'crud.dart';
class SecureStorage {
final FlutterSecureStorage _storage = const FlutterSecureStorage();
@@ -12,3 +18,41 @@ class SecureStorage {
return value;
}
}
const List<String> keysToFetch = [
'serverPHP',
'seferAlexandriaServer',
'seferPaymentServer',
'seferCairoServer',
'seferGizaServer',
];
class AppInitializer {
// final FlutterSecureStorage _storage = const FlutterSecureStorage();
Future<void> initializeApp() async {
// Check if app is running for the first time
// Loop through the keys and fetch their values
for (String key in keysToFetch) {
try {
String? value = await getKey(key); // Fetch from server
if (value != null) {
await box.write(key, value); // Save securely
}
} catch (e) {}
}
}
Future<String?> getKey(String key) async {
var res =
await CRUD().get(link: AppLink.getapiKey, payload: {"keyName": key});
if (res != 'failure') {
try {
var data = jsonDecode(res)['message'];
return data[key]?.toString();
} catch (e) {}
}
return null;
}
}