78 lines
2.3 KiB
Dart
78 lines
2.3 KiB
Dart
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();
|
|
|
|
void saveData(String key, value) async {
|
|
await _storage.write(key: key, value: value);
|
|
}
|
|
|
|
Future<String?> readData(String boxName) async {
|
|
final String? value = await _storage.read(key: boxName);
|
|
return value;
|
|
}
|
|
}
|
|
|
|
const List<String> keysToFetch = [
|
|
'serverPHP',
|
|
'seferAlexandriaServer',
|
|
'seferPaymentServer',
|
|
'seferCairoServer',
|
|
'seferGizaServer',
|
|
];
|
|
|
|
class AppInitializer {
|
|
List<Map<String, dynamic>> links = [];
|
|
|
|
Future<void> initializeApp() async {
|
|
await getKey();
|
|
await getAIKey('FCM_PRIVATE_KEY');
|
|
}
|
|
|
|
getAIKey(String key) async {
|
|
var res =
|
|
await CRUD().get(link: AppLink.getapiKey, payload: {"keyName": key});
|
|
if (res != 'failure') {
|
|
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');
|
|
}
|
|
}
|
|
}
|