39 lines
1.3 KiB
Dart
39 lines
1.3 KiB
Dart
import 'package:cheminova/models/notification_model.dart';
|
|
import 'package:cheminova/utils/api_urls.dart';
|
|
|
|
import '../utils/common_api_service.dart';
|
|
|
|
class NotificationApiService {
|
|
// Function to fetch notifications from the API
|
|
Future<List<NotificationModel>?> getNotification(String token) async {
|
|
try {
|
|
// Set the URL for fetching notifications
|
|
String url =ApiUrls.getNotificationUrl; // Base URL to fetch product manuals
|
|
// Make a GET request to the notification API
|
|
final response = await commonApiService<List<NotificationModel>>(
|
|
method: "GET",
|
|
url: url,
|
|
additionalHeaders: { // Pass the token here
|
|
'Authorization': 'Bearer $token',
|
|
},
|
|
fromJson: (json) {
|
|
if (json['notifications'] != null) {
|
|
// If notifications are present in the response, map them to NotificationModel objects
|
|
final List<NotificationModel> notification = (json['notifications'] as List)
|
|
.map((manualJson) => NotificationModel.fromJson(manualJson as Map<String, dynamic>))
|
|
.toList();
|
|
return notification;
|
|
} else {
|
|
return [];
|
|
}
|
|
},
|
|
);
|
|
return response;
|
|
} catch (e) {
|
|
|
|
print(e.toString());
|
|
return null;
|
|
}
|
|
}
|
|
}
|