feat: Phase 1 critical gaps — gamification API, Razorpay checkout, Google OAuth, notifications
- Fix gamification endpoints to use Node.js server (app.eventifyplus.com) - Replace 6 mock gamification methods with real API calls (dashboard, leaderboard, shop, redeem, submit) - Add booking models, service, payment service (Razorpay), checkout provider - Add 3-step CheckoutScreen with Razorpay native modal integration - Add Google OAuth login (Flutter + Django backend) - Add full notifications system (Django model + 3 endpoints + Flutter UI) - Register CheckoutProvider, NotificationProvider in main.dart MultiProvider - Wire notification bell in HomeScreen app bar - Add razorpay_flutter ^1.3.7 and google_sign_in ^6.2.2 packages
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
// lib/features/notifications/providers/notification_provider.dart
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import '../../../core/utils/error_utils.dart';
|
||||
import '../models/notification_model.dart';
|
||||
import '../services/notification_service.dart';
|
||||
|
||||
class NotificationProvider extends ChangeNotifier {
|
||||
final NotificationService _service = NotificationService();
|
||||
|
||||
List<NotificationModel> notifications = [];
|
||||
int unreadCount = 0;
|
||||
bool loading = false;
|
||||
String? error;
|
||||
|
||||
/// Load full notification list.
|
||||
Future<void> loadNotifications() async {
|
||||
loading = true;
|
||||
error = null;
|
||||
notifyListeners();
|
||||
try {
|
||||
notifications = await _service.getNotifications();
|
||||
unreadCount = notifications.where((n) => !n.isRead).length;
|
||||
} catch (e) {
|
||||
error = userFriendlyError(e);
|
||||
} finally {
|
||||
loading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
/// Lightweight count refresh (no full list fetch).
|
||||
Future<void> refreshUnreadCount() async {
|
||||
try {
|
||||
unreadCount = await _service.getUnreadCount();
|
||||
notifyListeners();
|
||||
} catch (_) {
|
||||
// Silently fail — badge just won't update
|
||||
}
|
||||
}
|
||||
|
||||
/// Mark single notification as read.
|
||||
Future<void> markAsRead(int id) async {
|
||||
try {
|
||||
await _service.markAsRead(notificationId: id);
|
||||
final idx = notifications.indexWhere((n) => n.id == id);
|
||||
if (idx >= 0) {
|
||||
notifications[idx].isRead = true;
|
||||
unreadCount = notifications.where((n) => !n.isRead).length;
|
||||
notifyListeners();
|
||||
}
|
||||
} catch (e) {
|
||||
error = userFriendlyError(e);
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
/// Mark all as read.
|
||||
Future<void> markAllAsRead() async {
|
||||
try {
|
||||
await _service.markAsRead(); // null = mark all
|
||||
for (final n in notifications) {
|
||||
n.isRead = true;
|
||||
}
|
||||
unreadCount = 0;
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
error = userFriendlyError(e);
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user