25-1/13/1-securejordan

This commit is contained in:
Hamza-Ayed
2025-01-13 22:10:47 +03:00
parent e8c3f8f339
commit a893e49282
36 changed files with 803 additions and 447 deletions

View File

@@ -2,8 +2,10 @@ import 'dart:convert';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import '../../constant/box_name.dart';
import '../../constant/links.dart';
import '../../main.dart';
import '../../print.dart';
import 'crud.dart';
class SecureStorage {
@@ -28,35 +30,24 @@ 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) {
print('Error fetching or saving key $key: $e');
}
}
await getKey();
}
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) {
print('Error parsing response for $key: $e');
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.write(BoxName.locationName, links);
}
} catch (e) {
print('Error fetching or decoding location data: $e');
}
return null;
}
}