This commit is contained in:
Hamza-Ayed
2024-09-10 03:10:04 +03:00
parent 3135187408
commit 6aeb091719
15 changed files with 419 additions and 284 deletions

View File

@@ -98,18 +98,19 @@ class LoginController extends GetxController {
'token': box.read(BoxName.tokenFCM),
'passengerID': box.read(BoxName.passengerID).toString()
});
Get.defaultDialog(
title: 'Device Change Detected'.tr,
middleText:
'You can only use one device at a time. This device will now be set as your active device.'
.tr,
textConfirm: 'OK'.tr,
confirmTextColor: Colors.white,
onConfirm: () {
Get.back();
Get.offAll(() => const MapPagePassenger());
},
);
// Get.defaultDialog(
// title: 'Device Change Detected'.tr,
// middleText:
// 'You can only use one device at a time. This device will now be set as your active device.'
// .tr,
// textConfirm: 'OK'.tr,
// confirmTextColor: Colors.white,
// onConfirm: () {
// Get.back();
// Get.offAll(() => const MapPagePassenger());
// },
// );
// Get.snackbar('title', 'message');
}
}
Get.offAll(() => const MapPagePassenger());

View File

@@ -20,7 +20,8 @@ import '../functions/sms_controller.dart';
class RegisterController extends GetxController {
final formKey = GlobalKey<FormState>();
final formKey3 = GlobalKey<FormState>();
List<String> countryCodes = ['+1', '+91', '+44'];
String selectedCountryCode = '+1';
TextEditingController firstNameController = TextEditingController();
TextEditingController lastNameController = TextEditingController();
TextEditingController emailController = TextEditingController();
@@ -40,6 +41,11 @@ class RegisterController extends GetxController {
super.onInit();
}
void updateCountryCode(String newCode) {
selectedCountryCode = newCode;
update();
}
void startTimer() {
_timer?.cancel(); // Cancel any existing timer
_timer = Timer.periodic(const Duration(seconds: 1), (timer) {

View File

@@ -11,9 +11,10 @@ class AccessTokenManager {
factory AccessTokenManager(String jsonKey) {
if (_instance._isServiceAccountKeyInitialized()) {
// Prevent re-initialization
print('Service account key already initialized.');
return _instance;
}
print('Initializing service account key.');
_instance.serviceAccountJsonKey = jsonKey;
return _instance;
}
@@ -28,23 +29,45 @@ class AccessTokenManager {
}
Future<String> getAccessToken() async {
if (_accessToken != null && DateTime.now().isBefore(_expiryDate!)) {
return _accessToken!.data;
}
print('Attempting to get a new access token...');
try {
// Parse service account credentials from JSON
print('Parsing service account credentials...');
final serviceAccountCredentials = ServiceAccountCredentials.fromJson(
json.decode(serviceAccountJsonKey));
// Log service account email (or other non-sensitive information)
print('Service account email: ${serviceAccountCredentials.email}');
// Create an authenticated client via the service account
print('Creating authenticated client via service account...');
final client = await clientViaServiceAccount(
serviceAccountCredentials,
['https://www.googleapis.com/auth/firebase.messaging'],
);
// Log successful client creation
print('Authenticated client created successfully.');
// Update the access token and expiry date
_accessToken = client.credentials.accessToken;
_expiryDate = client.credentials.accessToken.expiry;
// Log the obtained token and expiry time
print('Access token obtained: ${_accessToken!.data}');
print('Token expiry date: $_expiryDate');
// Close the client to prevent resource leaks
print('Closing authenticated client...');
client.close();
// Return the newly fetched access token
return _accessToken!.data;
} catch (e) {
throw Exception('Failed to obtain access token');
// Log error if token fetch fails
print('Failed to obtain a new access token: $e');
throw Exception('Failed to obtain a new access token: $e');
}
}
}

View File

@@ -610,13 +610,27 @@ class FirebaseMessagesController extends GetxController {
);
if (response.statusCode == 200) {
print(
'Notification sent successfully. Status code: ${response.statusCode}');
print('Notification sent successfully.');
print('Response body: ${response.body}');
} else {
print(
'Failed to send notification. Status code: ${response.statusCode}');
print('Response body: ${response.body}');
// Parse the response body to handle specific errors like 'UNREGISTERED'
final responseBody = jsonDecode(response.body);
if (responseBody['error'] != null &&
responseBody['error']['status'] == 'NOT_FOUND' &&
responseBody['error']['details'] != null) {
for (var detail in responseBody['error']['details']) {
if (detail['errorCode'] == 'UNREGISTERED') {
print(
'FCM token is unregistered or invalid. Consider removing this token.');
// Remove the unregistered token from your database here.
// Example: removeTokenFromDatabase(token);
}
}
}
}
} catch (e) {
print('Error sending notification: $e');
@@ -721,15 +735,27 @@ class FirebaseMessagesController extends GetxController {
},
}),
);
if (response.statusCode == 200) {
print(
'Notification sent successfully. Status code: ${response.statusCode}');
print('Notification sent successfully.');
print('Response body: ${response.body}');
} else {
print(
'Failed to send notification. Status code: ${response.statusCode}');
print('Response body: ${response.body}');
// Parse the response body to handle specific errors like 'UNREGISTERED'
final responseBody = jsonDecode(response.body);
if (responseBody['error'] != null &&
responseBody['error']['status'] == 'NOT_FOUND' &&
responseBody['error']['details'] != null) {
for (var detail in responseBody['error']['details']) {
if (detail['errorCode'] == 'UNREGISTERED') {
print(
'FCM token is unregistered or invalid. Consider removing this token.');
// Remove the unregistered token from your database if needed
}
}
}
}
} catch (e) {
print('Error sending notification: $e');
@@ -785,10 +811,26 @@ class FirebaseMessagesController extends GetxController {
);
if (response.statusCode == 200) {
// Notification sent successfully
print('Notification sent successfully.');
print('Response body: ${response.body}');
} else {
// Handle error response
'Failed to send notification. Status code: ${response.statusCode}';
print(
'Failed to send notification. Status code: ${response.statusCode}');
print('Response body: ${response.body}');
// Parse the response body to handle specific errors like 'UNREGISTERED'
final responseBody = jsonDecode(response.body);
if (responseBody['error'] != null &&
responseBody['error']['status'] == 'NOT_FOUND' &&
responseBody['error']['details'] != null) {
for (var detail in responseBody['error']['details']) {
if (detail['errorCode'] == 'UNREGISTERED') {
print(
'FCM token is unregistered or invalid. Consider removing this token.');
// Remove the unregistered token from your database if needed
}
}
}
}
} catch (e) {
// Handle other exceptions

View File

@@ -3758,7 +3758,7 @@ class MapPassengerController extends GetxController {
addCustomStepIcon();
addCustomStartIcon();
addCustomEndIcon();
getLocation();
await getLocation();
// await addToken();
getKazanPercent();

View File

@@ -596,7 +596,7 @@ iOS [https://getapp.cc/app/6458734951]
'الرَّجَاء التَّحَرُّك إِلَى السَّيَّارَة الآن',
'You will receive a code in WhatsApp Messenger':
"سوف تتلقى رمزًا في واتساب ماسنجر",
'Balash': 'أوفر كار',
'Awfar Car': 'أوفر كار',
"Old and affordable, perfect for budget rides.":
"سيارة ميسورة التكلفة، مثالية للرحلات الاقتصادية.",
" If you need to reach me, please contact the driver directly at":