9/21/2
This commit is contained in:
@@ -11,6 +11,7 @@ import '../../constant/colors.dart';
|
||||
import '../../constant/links.dart';
|
||||
import '../../constant/style.dart';
|
||||
import '../../main.dart';
|
||||
import '../../print.dart';
|
||||
import '../../views/widgets/elevated_btn.dart';
|
||||
import '../notification_controller.dart';
|
||||
import 'local_notification.dart';
|
||||
@@ -83,34 +84,38 @@ class FirebaseMessagesController extends GetxController {
|
||||
|
||||
var currentPage = 1;
|
||||
var totalPages = 1;
|
||||
Future<void> getAllTokenDrivers({int page = 1}) async {
|
||||
Future<void> getAllTokenDrivers() async {
|
||||
isLoading = true;
|
||||
try {
|
||||
var res = await http.post(
|
||||
Uri.parse(AppLink.getAllTokenDrivers),
|
||||
Uri.parse(AppLink.getDriversPhonesAndTokens),
|
||||
headers: {
|
||||
'Authorization':
|
||||
'Basic ${base64Encode(utf8.encode(AK.basicAuthCredentials))}',
|
||||
},
|
||||
body: {
|
||||
'page': page.toString(),
|
||||
// 'page': page.toString(),
|
||||
},
|
||||
);
|
||||
|
||||
var jsonResponse = jsonDecode(res.body);
|
||||
Log.print('jsonResponse: ${jsonResponse}');
|
||||
if (jsonResponse['status'] == 'success') {
|
||||
var newData = jsonResponse['data'] as List;
|
||||
if (page == 1) {
|
||||
dataTokens.clear();
|
||||
tokens.clear();
|
||||
}
|
||||
dataTokens.addAll(newData);
|
||||
for (var item in newData) {
|
||||
tokens.add(item['token']);
|
||||
}
|
||||
currentPage = int.parse(jsonResponse['currentPage']);
|
||||
totalPages = jsonResponse['totalPages'];
|
||||
box.write(BoxName.tokensDrivers, tokens);
|
||||
// var newData = jsonResponse['data'] as List;
|
||||
// Log.print('newData: ${newData}');
|
||||
// // if (page == 1) {
|
||||
// // dataTokens.clear();
|
||||
// // tokens.clear();
|
||||
// // }
|
||||
// dataTokens.addAll(newData);
|
||||
// for (var item in newData) {
|
||||
// tokens.add(item['token']);
|
||||
// }
|
||||
// currentPage = int.parse(jsonResponse['currentPage']);
|
||||
// totalPages = jsonResponse['totalPages'];
|
||||
box.write(BoxName.tokensDrivers, jsonResponse);
|
||||
Log.print(
|
||||
'box.write(BoxName.tokensDrivers: ${box.read(BoxName.tokensDrivers)}');
|
||||
} else {
|
||||
Get.defaultDialog(
|
||||
title: "Warning", middleText: "No more data available");
|
||||
@@ -166,17 +171,20 @@ class FirebaseMessagesController extends GetxController {
|
||||
bool isSendingNotifications = false;
|
||||
Future<void> loadAllPagesAndSendNotifications() async {
|
||||
isSendingNotifications = true;
|
||||
currentPage = 1;
|
||||
// currentPage = 1;
|
||||
|
||||
while (currentPage <= totalPages) {
|
||||
await getAllTokenDrivers(page: currentPage);
|
||||
await NotificationController().sendNotificationDrivers();
|
||||
print(tokens);
|
||||
if (currentPage < totalPages) {
|
||||
await Future.delayed(const Duration(seconds: 3));
|
||||
}
|
||||
currentPage++;
|
||||
}
|
||||
// while (currentPage <= totalPages) {
|
||||
// await getAllTokenDrivers(page: currentPage);
|
||||
await getAllTokenDrivers();
|
||||
// Log.print('tokens: ${tokens}');
|
||||
await NotificationController().sendNotificationDrivers();
|
||||
// print(tokens);
|
||||
|
||||
// if (currentPage < totalPages) {
|
||||
// await Future.delayed(const Duration(seconds: 3));
|
||||
// }
|
||||
// currentPage++;
|
||||
// }
|
||||
|
||||
isSendingNotifications = false;
|
||||
Get.snackbar("Success", "All notifications sent!");
|
||||
@@ -189,7 +197,7 @@ class FirebaseMessagesController extends GetxController {
|
||||
|
||||
while (currentPagePassenger <= totalPagesPassenger) {
|
||||
await getAllTokenPassenger(page: currentPagePassenger);
|
||||
await NotificationController().sendNotificationDrivers();
|
||||
await NotificationController().sendNotificationPassengers();
|
||||
print(tokensPassengers);
|
||||
if (currentPagePassenger < totalPagesPassenger) {
|
||||
await Future.delayed(const Duration(seconds: 3));
|
||||
@@ -596,6 +604,7 @@ class FirebaseMessagesController extends GetxController {
|
||||
|
||||
// Obtain an OAuth 2.0 access token
|
||||
final accessToken = await accessTokenManager.getAccessToken();
|
||||
// Log.print('accessToken: ${accessToken}');
|
||||
|
||||
// Send the notification
|
||||
final response = await http.post(
|
||||
@@ -612,9 +621,6 @@ class FirebaseMessagesController extends GetxController {
|
||||
'title': title,
|
||||
'body': body,
|
||||
},
|
||||
'data': {
|
||||
'DriverList': jsonEncode([]),
|
||||
},
|
||||
'android': {
|
||||
'notification': {
|
||||
'sound': tone,
|
||||
@@ -634,11 +640,11 @@ class FirebaseMessagesController extends GetxController {
|
||||
if (response.statusCode == 200) {
|
||||
print(
|
||||
'Notification sent successfully. Status code: ${response.statusCode}');
|
||||
print('Response body: ${response.body}');
|
||||
// print('Response body: ${response.body}');
|
||||
} else {
|
||||
print(
|
||||
'Failed to send notification. Status code: ${response.statusCode}');
|
||||
print('Response body: ${response.body}');
|
||||
// print('Response body: ${response.body}');
|
||||
}
|
||||
} catch (e) {
|
||||
print('Error sending notification: $e');
|
||||
|
||||
Reference in New Issue
Block a user