sc-android-app/lib/provider/notification_provider.dart

64 lines
1.6 KiB
Dart

import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../models/notification_list_response.dart';
import '../services/api_client.dart';
import '../services/api_urls.dart';
class NotificationProvider extends ChangeNotifier {
NotificationProvider() {
// getNotification();
}
final _apiClient = ApiClient();
List<Notifications> notificationList = [];
bool _isLoading = false;
bool get isLoading => _isLoading;
void setLoading(bool loading) {
_isLoading = loading;
notifyListeners();
}
// Future<void> getNotification(String date) async {
// final String url = "${ApiUrls.notificationUrl}?Date=$date";
// setLoading(true);
// try {
// Response response = await _apiClient.get(url);
// setLoading(false);
// if (response.statusCode == 200) {
// final data = NotificationListResponse.fromJson(response.data);
// notificationList = data.notifications ?? [];
// notifyListeners();
// }
// } catch (e) {
// setLoading(false);
// }
// }
Future<void> getNotification(String date) async {
if (date.isEmpty) return; // Invalid call ko prevent karein
final String url = "${ApiUrls.notificationUrl}?Date=$date";
setLoading(true);
try {
Response response = await _apiClient.get(url);
if (response.statusCode == 200) {
final data = NotificationListResponse.fromJson(response.data);
notificationList = data.notifications ?? [];
} else {
notificationList = [];
}
} catch (e) {
notificationList = [];
}
setLoading(false);
notifyListeners();
}
}