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

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-04 15:46:53 +05:30
parent 847577c09d
commit 29e326b8fc
24 changed files with 1663 additions and 164 deletions

View File

@@ -0,0 +1,33 @@
// lib/features/notifications/models/notification_model.dart
class NotificationModel {
final int id;
final String title;
final String message;
final String type; // event, promo, system, booking
bool isRead;
final DateTime createdAt;
final String? actionUrl;
NotificationModel({
required this.id,
required this.title,
required this.message,
this.type = 'system',
this.isRead = false,
required this.createdAt,
this.actionUrl,
});
factory NotificationModel.fromJson(Map<String, dynamic> json) {
return NotificationModel(
id: (json['id'] as num?)?.toInt() ?? 0,
title: json['title'] as String? ?? '',
message: json['message'] as String? ?? '',
type: json['notification_type'] as String? ?? json['type'] as String? ?? 'system',
isRead: (json['is_read'] as bool?) ?? false,
createdAt: DateTime.tryParse(json['created_at'] as String? ?? '') ?? DateTime.now(),
actionUrl: json['action_url'] as String?,
);
}
}

View File

@@ -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();
}
}
}

View File

@@ -0,0 +1,41 @@
// lib/features/notifications/services/notification_service.dart
import '../../../core/api/api_client.dart';
import '../../../core/api/api_endpoints.dart';
import '../models/notification_model.dart';
class NotificationService {
final ApiClient _api = ApiClient();
/// Fetch notifications for current user (paginated).
Future<List<NotificationModel>> getNotifications({int page = 1, int pageSize = 20}) async {
final res = await _api.post(
ApiEndpoints.notificationList,
body: {'page': page, 'page_size': pageSize},
);
final rawList = res['notifications'] ?? res['data'] ?? [];
if (rawList is List) {
return rawList
.map((e) => NotificationModel.fromJson(Map<String, dynamic>.from(e as Map)))
.toList();
}
return [];
}
/// Mark a single notification as read, or all if [notificationId] is null.
Future<void> markAsRead({int? notificationId}) async {
final body = <String, dynamic>{};
if (notificationId != null) {
body['notification_id'] = notificationId;
} else {
body['mark_all'] = true;
}
await _api.post(ApiEndpoints.notificationMarkRead, body: body);
}
/// Get unread notification count (lightweight).
Future<int> getUnreadCount() async {
final res = await _api.post(ApiEndpoints.notificationCount);
return (res['unread_count'] as num?)?.toInt() ?? 0;
}
}

View File

@@ -0,0 +1,61 @@
// lib/features/notifications/widgets/notification_bell.dart
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../providers/notification_provider.dart';
import 'notification_panel.dart';
class NotificationBell extends StatelessWidget {
const NotificationBell({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Consumer<NotificationProvider>(
builder: (context, provider, _) {
return GestureDetector(
onTap: () => _showPanel(context),
child: Stack(
clipBehavior: Clip.none,
children: [
const Padding(
padding: EdgeInsets.all(8.0),
child: Icon(Icons.notifications_outlined, size: 26, color: Colors.black87),
),
if (provider.unreadCount > 0)
Positioned(
right: 4,
top: 4,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 2),
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(10),
),
constraints: const BoxConstraints(minWidth: 18, minHeight: 18),
child: Text(
provider.unreadCount > 99 ? '99+' : '${provider.unreadCount}',
style: const TextStyle(color: Colors.white, fontSize: 10, fontWeight: FontWeight.w600),
textAlign: TextAlign.center,
),
),
),
],
),
);
},
);
}
void _showPanel(BuildContext context) {
context.read<NotificationProvider>().loadNotifications();
showModalBottomSheet(
context: context,
isScrollControlled: true,
backgroundColor: Colors.transparent,
builder: (_) => ChangeNotifierProvider.value(
value: context.read<NotificationProvider>(),
child: const NotificationPanel(),
),
);
}
}

View File

@@ -0,0 +1,101 @@
// lib/features/notifications/widgets/notification_panel.dart
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../providers/notification_provider.dart';
import 'notification_tile.dart';
class NotificationPanel extends StatelessWidget {
const NotificationPanel({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return DraggableScrollableSheet(
expand: false,
initialChildSize: 0.6,
minChildSize: 0.35,
maxChildSize: 0.95,
builder: (context, scrollController) {
return Container(
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.vertical(top: Radius.circular(24)),
),
child: Column(
children: [
// Handle bar
Center(
child: Container(
margin: const EdgeInsets.only(top: 12, bottom: 8),
width: 48,
height: 5,
decoration: BoxDecoration(
color: Colors.grey.shade300,
borderRadius: BorderRadius.circular(3),
),
),
),
// Header
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 8),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text('Notifications', style: TextStyle(fontSize: 20, fontWeight: FontWeight.w700)),
Consumer<NotificationProvider>(
builder: (_, provider, __) {
if (provider.unreadCount == 0) return const SizedBox.shrink();
return TextButton(
onPressed: provider.markAllAsRead,
child: const Text('Mark all read', style: TextStyle(fontSize: 13)),
);
},
),
],
),
),
const Divider(height: 1),
// List
Expanded(
child: Consumer<NotificationProvider>(
builder: (_, provider, __) {
if (provider.loading) {
return const Center(child: CircularProgressIndicator());
}
if (provider.notifications.isEmpty) {
return Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.notifications_none, size: 56, color: Colors.grey.shade300),
const SizedBox(height: 12),
Text('No notifications yet', style: TextStyle(color: Colors.grey.shade500, fontSize: 15)),
],
),
);
}
return ListView.separated(
controller: scrollController,
padding: const EdgeInsets.symmetric(vertical: 8),
itemCount: provider.notifications.length,
separatorBuilder: (_, __) => const Divider(height: 1, indent: 72),
itemBuilder: (ctx, idx) {
final notif = provider.notifications[idx];
return NotificationTile(
notification: notif,
onTap: () {
if (!notif.isRead) provider.markAsRead(notif.id);
},
);
},
);
},
),
),
],
),
);
},
);
}
}

View File

@@ -0,0 +1,94 @@
// lib/features/notifications/widgets/notification_tile.dart
import 'package:flutter/material.dart';
import '../models/notification_model.dart';
class NotificationTile extends StatelessWidget {
final NotificationModel notification;
final VoidCallback? onTap;
const NotificationTile({Key? key, required this.notification, this.onTap}) : super(key: key);
@override
Widget build(BuildContext context) {
return InkWell(
onTap: onTap,
child: Container(
color: notification.isRead ? Colors.transparent : const Color(0xFFF0F4FF),
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 14),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildIcon(),
const SizedBox(width: 14),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
notification.title,
style: TextStyle(
fontWeight: notification.isRead ? FontWeight.w400 : FontWeight.w600,
fontSize: 14,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 4),
Text(
notification.message,
style: TextStyle(color: Colors.grey.shade600, fontSize: 13),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 6),
Text(
_timeAgo(notification.createdAt),
style: TextStyle(color: Colors.grey.shade400, fontSize: 12),
),
],
),
),
],
),
),
);
}
Widget _buildIcon() {
final config = _typeConfig(notification.type);
return Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: config.color.withOpacity(0.15),
shape: BoxShape.circle,
),
child: Icon(config.icon, color: config.color, size: 20),
);
}
static _TypeConfig _typeConfig(String type) {
switch (type) {
case 'event': return _TypeConfig(Colors.blue, Icons.event);
case 'promo': return _TypeConfig(Colors.green, Icons.local_offer);
case 'booking': return _TypeConfig(Colors.orange, Icons.confirmation_number);
default: return _TypeConfig(Colors.grey, Icons.info_outline);
}
}
static String _timeAgo(DateTime dt) {
final diff = DateTime.now().difference(dt);
if (diff.inMinutes < 1) return 'Just now';
if (diff.inMinutes < 60) return '${diff.inMinutes}m ago';
if (diff.inHours < 24) return '${diff.inHours}h ago';
if (diff.inDays < 7) return '${diff.inDays}d ago';
return '${dt.day}/${dt.month}/${dt.year}';
}
}
class _TypeConfig {
final Color color;
final IconData icon;
const _TypeConfig(this.color, this.icon);
}