import 'dart:convert'; import 'package:wanisclient/config/constants/app_constant.dart'; import 'package:wanisclient/providers/utils_singleton.dart'; import 'package:http/http.dart' as http; import '../config/api_response.dart'; import '../models/NotificationModelFCM.dart'; class NotificationFCMService { Future>> fetchNotificationsFCM({ required int page, required int size, }) async { try { final response = await http.get( Uri.https( baseUrl, '/api/v1/notifications/all_my_notification', { 'page': page.toString(), 'size': size.toString(), }, ), headers: { 'Accept': 'application/json', 'Authorization': 'Bearer ${utils.token}', }, ); print("====================*************=======> $response "); if (response.statusCode == 200) { final data = jsonDecode(response.body); final List results = data['result'] ?? []; print("====================11=======> $results "); final notifications = results.map((json) => NotificationModelFCM.fromJson(json)).toList(); print("====================22=======> ${notifications.first.title} "); return APIResponse( data: notifications, statusCode: 200, totalPages: data['totalPages'], ); } else { final data = jsonDecode(response.body); print("====================33=======> $data "); return APIResponse( data: [], errorMessage: data['message'] ?? 'Failed to load notifications', statusCode: response.statusCode, ); } } catch (e) { return APIResponse( data: [], errorMessage: 'Error: $e', statusCode: null, ); } } }