25-1/28/1

This commit is contained in:
Hamza-Ayed
2025-01-28 01:03:39 +03:00
parent 63681f104c
commit f217b5a34f
102 changed files with 7253 additions and 3945 deletions

View File

@@ -1,10 +1,13 @@
import 'dart:convert';
import 'package:SEFER/constant/box_name.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import '../../constant/links.dart';
import '../../main.dart';
import '../../print.dart';
import 'crud.dart';
import 'encrypt_decrypt.dart';
class SecureStorage {
final FlutterSecureStorage _storage = const FlutterSecureStorage();
@@ -28,31 +31,47 @@ const List<String> keysToFetch = [
];
class AppInitializer {
// final FlutterSecureStorage _storage = const FlutterSecureStorage();
List<Map<String, dynamic>> links = [];
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) {}
}
await getKey();
await getAIKey('FCM_PRIVATE_KEY');
}
Future<String?> getKey(String key) async {
getAIKey(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) {}
var d = jsonDecode(res)['message'];
storage.write(key: 'FCM_PRIVATE_KEY', value: d[key].toString());
// return d[key].toString();
} else {}
}
Future<void> getKey() async {
try {
var res =
await CRUD().get(link: AppLink.getLocationAreaLinks, payload: {});
// Log.print('res: ${res}');
if (res != 'failure') {
links = List<Map<String, dynamic>>.from(jsonDecode(res)['message']);
await box.remove(BoxName.locationName);
await box.remove(BoxName.basicLink);
await box.remove(links[4]['name']);
await box.remove(links[1]['name']);
await box.remove(links[2]['name']);
await box.write(BoxName.locationName, links);
await box.write(BoxName.basicLink,
encryptionHelper.decryptData(links[0]['server_link']));
await box.write(links[2]['name'],
encryptionHelper.decryptData(links[2]['server_link']));
await box.write(links[1]['name'],
encryptionHelper.decryptData(links[1]['server_link']));
await box.write(BoxName.paymentLink,
encryptionHelper.decryptData(links[4]['server_link']));
}
} catch (e) {
print('Error fetching or decoding location data: $e');
}
return null;
}
}