pd-android-app/lib/controller/notification_controller.dart
saritabirare ff065bdc16 1) annaucement api integration done
2)Billto and shipTo api integration
2024-10-22 10:36:49 +05:30

40 lines
1.2 KiB
Dart

import 'package:cheminova/models/notification_model.dart';
import 'package:get/get.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'notification_api_service.dart';
class NotificationController extends GetxController {
var isLoading = false.obs;
var notificationList = <NotificationModel>[].obs;
final NotificationService _notificationApiService = NotificationService();
// Function to fetch notifications from the API with the selected date
void fetchNotificationApiService(String date) async {
try {
isLoading(true);
// Retrieve token from a secure source
SharedPreferences prefs = await SharedPreferences.getInstance();
String? token = prefs.getString('token');
if (token == null) {
print("Token is null");
return;
}
// Fetch notifications by date
List<NotificationModel>? notifications = await _notificationApiService.fetchNotifications(token, date);
if (notifications != null && notifications.isNotEmpty) {
notificationList.value = notifications;
} else {
notificationList.clear();
}
} catch (e) {
print("Error fetching notifications: $e");
} finally {
isLoading(false);
}
}
}