27 lines
790 B
Dart
27 lines
790 B
Dart
import 'package:cheminova/utils/api_urls.dart';
|
|
import 'package:dio/dio.dart';
|
|
|
|
import '../models/annauncement_model.dart';
|
|
|
|
class AnnouncementService {
|
|
final Dio _dio = Dio();
|
|
|
|
Future<List<AnnouncementModel>> fetchAnnouncements(String token) async {
|
|
final String url = ApiUrls.AnnaouncementUrl;
|
|
try {
|
|
_dio.options.headers['Authorization'] = 'Bearer $token';
|
|
final Response response = await _dio.get(url);
|
|
|
|
if (response.statusCode == 200) {
|
|
|
|
List<dynamic> data = response.data;
|
|
return data.map((announcement) => AnnouncementModel.fromJson(announcement)).toList();
|
|
} else {
|
|
throw Exception('Failed to load announcements');
|
|
}
|
|
} catch (e) {
|
|
throw Exception('Error occurred while fetching announcements: $e');
|
|
}
|
|
}
|
|
}
|