This commit is contained in:
Phuoc Nguyen
2025-11-03 15:02:33 +07:00
parent 56c470baa1
commit aa3a52bba7
17 changed files with 1393 additions and 345 deletions

View File

@@ -0,0 +1,181 @@
/// Notification Local Data Source
///
/// Provides mock notification data for development.
/// Simulates API responses with JSON data.
library;
/// Notification Local Data Source
///
/// Returns raw JSON data as if from API.
class NotificationLocalDataSource {
/// Mock notifications data (as JSON from API)
final List<Map<String, dynamic>> _mockNotifications = [
// Points earned (General - unread)
{
'notification_id': 'notif_001',
'user_id': 'user_001',
'type': 'loyalty_points_earned',
'title': 'Chúc mừng! Bạn vừa nhận 500 điểm thưởng',
'message':
'Hoàn thành đơn hàng DH2023120801 và nhận 500 điểm vào tài khoản.',
'data': {'points': 500, 'order_id': 'DH2023120801'},
'is_read': false,
'is_pushed': true,
'created_at': '2025-11-03T05:00:00.000Z',
'read_at': null,
},
// Promotion (General - unread)
{
'notification_id': 'notif_002',
'user_id': 'user_001',
'type': 'promotion_flash_sale',
'title': 'Flash Sale cuối năm - Giảm đến 50%',
'message':
'Chương trình khuyến mãi đặc biệt chỉ còn 2 ngày. Nhanh tay săn ngay!',
'data': {'promotion_id': 'PROMO_FLASH_DEC'},
'is_read': false,
'is_pushed': true,
'created_at': '2025-11-03T02:00:00.000Z',
'read_at': null,
},
// Order shipping (Order - unread)
{
'notification_id': 'notif_003',
'user_id': 'user_001',
'type': 'order_shipping',
'title': 'Đơn hàng đang được giao',
'message':
'Đơn hàng DH2023120701 đang trên đường giao đến bạn. Dự kiến giao trong hôm nay.',
'data': {'order_id': 'DH2023120701'},
'is_read': false,
'is_pushed': true,
'created_at': '2025-11-02T07:00:00.000Z',
'read_at': null,
},
// Tier upgrade (General - read)
{
'notification_id': 'notif_004',
'user_id': 'user_001',
'type': 'loyalty_tier_upgrade',
'title': 'Sắp lên hạng Platinum',
'message':
'Bạn chỉ còn 2,250 điểm nữa để đạt hạng Platinum với nhiều ưu đãi hấp dẫn.',
'data': {
'current_tier': 'gold',
'next_tier': 'platinum',
'points_needed': 2250
},
'is_read': true,
'is_pushed': true,
'created_at': '2025-11-01T07:00:00.000Z',
'read_at': '2025-11-02T19:00:00.000Z',
},
// Event (General - read)
{
'notification_id': 'notif_005',
'user_id': 'user_001',
'type': 'event_invitation',
'title': 'Sự kiện VIP sắp diễn ra',
'message':
'Mời bạn tham gia sự kiện ra mắt bộ sưu tập gạch mới vào 15/12/2023 tại showroom.',
'data': {'event_id': 'EVENT_DEC_2023', 'date': '2023-12-15'},
'is_read': true,
'is_pushed': true,
'created_at': '2025-10-31T07:00:00.000Z',
'read_at': '2025-11-01T23:00:00.000Z',
},
// Order confirmed (Order - read)
{
'notification_id': 'notif_006',
'user_id': 'user_001',
'type': 'order_confirmed',
'title': 'Xác nhận đơn hàng thành công',
'message':
'Đơn hàng DH2023120601 đã được xác nhận. Chúng tôi sẽ sớm chuẩn bị và giao hàng.',
'data': {'order_id': 'DH2023120601'},
'is_read': true,
'is_pushed': true,
'created_at': '2025-10-30T07:00:00.000Z',
'read_at': '2025-10-31T21:00:00.000Z',
},
// Birthday (General - read)
{
'notification_id': 'notif_007',
'user_id': 'user_001',
'type': 'birthday_reward',
'title': 'Sinh nhật sắp đến',
'message':
'Chúc mừng sinh nhật! Bạn sẽ nhận 500 điểm thưởng vào ngày 20/12.',
'data': {'birthday_date': '2023-12-20', 'points': 500},
'is_read': true,
'is_pushed': true,
'created_at': '2025-10-27T07:00:00.000Z',
'read_at': '2025-10-28T17:00:00.000Z',
},
];
/// Get all notifications (returns JSON data)
Future<List<Map<String, dynamic>>> getAllNotifications() async {
await Future.delayed(const Duration(milliseconds: 300));
return List.from(_mockNotifications);
}
/// Get notifications by category
Future<List<Map<String, dynamic>>> getNotificationsByCategory(
String category) async {
await Future.delayed(const Duration(milliseconds: 200));
if (category == 'general') {
return _mockNotifications
.where((n) =>
!(n['type'] as String).toLowerCase().contains('order') ||
(n['type'] as String).toLowerCase().contains('loyalty') ||
(n['type'] as String).toLowerCase().contains('promotion') ||
(n['type'] as String).toLowerCase().contains('event') ||
(n['type'] as String).toLowerCase().contains('birthday'))
.toList();
} else if (category == 'order') {
return _mockNotifications
.where((n) => (n['type'] as String).toLowerCase().contains('order'))
.toList();
}
return List.from(_mockNotifications);
}
/// Get unread count
Future<int> getUnreadCount() async {
await Future.delayed(const Duration(milliseconds: 100));
return _mockNotifications.where((n) => !(n['is_read'] as bool)).length;
}
/// Mark notification as read
Future<void> markAsRead(String notificationId) async {
await Future.delayed(const Duration(milliseconds: 150));
final index = _mockNotifications
.indexWhere((n) => n['notification_id'] == notificationId);
if (index != -1) {
_mockNotifications[index]['is_read'] = true;
_mockNotifications[index]['read_at'] = DateTime.now().toIso8601String();
}
}
/// Mark all notifications as read
Future<void> markAllAsRead() async {
await Future.delayed(const Duration(milliseconds: 200));
for (var notification in _mockNotifications) {
if (!(notification['is_read'] as bool)) {
notification['is_read'] = true;
notification['read_at'] = DateTime.now().toIso8601String();
}
}
}
}

View File

@@ -1,56 +1,45 @@
import 'dart:convert';
import 'package:hive_ce/hive.dart';
import 'package:worker/core/constants/storage_constants.dart';
/// Notification Model
///
/// Converts JSON data from API to domain entity.
library;
part 'notification_model.g.dart';
import 'package:worker/features/notifications/domain/entities/notification.dart';
@HiveType(typeId: HiveTypeIds.notificationModel)
class NotificationModel extends HiveObject {
NotificationModel({required this.notificationId, required this.userId, required this.type, required this.title, required this.message, this.data, required this.isRead, required this.isPushed, required this.createdAt, this.readAt});
@HiveField(0) final String notificationId;
@HiveField(1) final String userId;
@HiveField(2) final String type;
@HiveField(3) final String title;
@HiveField(4) final String message;
@HiveField(5) final String? data;
@HiveField(6) final bool isRead;
@HiveField(7) final bool isPushed;
@HiveField(8) final DateTime createdAt;
@HiveField(9) final DateTime? readAt;
/// Notification Model
///
/// Handles JSON serialization/deserialization.
class NotificationModel {
/// Convert JSON to Notification entity
static Notification fromJson(Map<String, dynamic> json) {
return Notification(
notificationId: json['notification_id'] as String,
userId: json['user_id'] as String,
type: json['type'] as String,
title: json['title'] as String,
message: json['message'] as String,
data: json['data'] as Map<String, dynamic>?,
isRead: json['is_read'] as bool? ?? false,
isPushed: json['is_pushed'] as bool? ?? false,
createdAt: DateTime.parse(json['created_at'] as String),
readAt: json['read_at'] != null
? DateTime.parse(json['read_at'] as String)
: null,
);
}
factory NotificationModel.fromJson(Map<String, dynamic> json) => NotificationModel(
notificationId: json['notification_id'] as String,
userId: json['user_id'] as String,
type: json['type'] as String,
title: json['title'] as String,
message: json['message'] as String,
data: json['data'] != null ? jsonEncode(json['data']) : null,
isRead: json['is_read'] as bool? ?? false,
isPushed: json['is_pushed'] as bool? ?? false,
createdAt: DateTime.parse(json['created_at']?.toString() ?? ''),
readAt: json['read_at'] != null ? DateTime.parse(json['read_at']?.toString() ?? '') : null,
);
Map<String, dynamic> toJson() => {
'notification_id': notificationId,
'user_id': userId,
'type': type,
'title': title,
'message': message,
'data': data != null ? jsonDecode(data!) : null,
'is_read': isRead,
'is_pushed': isPushed,
'created_at': createdAt.toIso8601String(),
'read_at': readAt?.toIso8601String(),
};
Map<String, dynamic>? get dataMap {
if (data == null) return null;
try {
return jsonDecode(data!) as Map<String, dynamic>;
} catch (e) {
return null;
}
/// Convert Notification entity to JSON
static Map<String, dynamic> toJson(Notification notification) {
return {
'notification_id': notification.notificationId,
'user_id': notification.userId,
'type': notification.type,
'title': notification.title,
'message': notification.message,
'data': notification.data,
'is_read': notification.isRead,
'is_pushed': notification.isPushed,
'created_at': notification.createdAt.toIso8601String(),
'read_at': notification.readAt?.toIso8601String(),
};
}
}

View File

@@ -1,68 +0,0 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'notification_model.dart';
// **************************************************************************
// TypeAdapterGenerator
// **************************************************************************
class NotificationModelAdapter extends TypeAdapter<NotificationModel> {
@override
final typeId = 20;
@override
NotificationModel read(BinaryReader reader) {
final numOfFields = reader.readByte();
final fields = <int, dynamic>{
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
};
return NotificationModel(
notificationId: fields[0] as String,
userId: fields[1] as String,
type: fields[2] as String,
title: fields[3] as String,
message: fields[4] as String,
data: fields[5] as String?,
isRead: fields[6] as bool,
isPushed: fields[7] as bool,
createdAt: fields[8] as DateTime,
readAt: fields[9] as DateTime?,
);
}
@override
void write(BinaryWriter writer, NotificationModel obj) {
writer
..writeByte(10)
..writeByte(0)
..write(obj.notificationId)
..writeByte(1)
..write(obj.userId)
..writeByte(2)
..write(obj.type)
..writeByte(3)
..write(obj.title)
..writeByte(4)
..write(obj.message)
..writeByte(5)
..write(obj.data)
..writeByte(6)
..write(obj.isRead)
..writeByte(7)
..write(obj.isPushed)
..writeByte(8)
..write(obj.createdAt)
..writeByte(9)
..write(obj.readAt);
}
@override
int get hashCode => typeId.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is NotificationModelAdapter &&
runtimeType == other.runtimeType &&
typeId == other.typeId;
}

View File

@@ -0,0 +1,55 @@
/// Notification Repository Implementation
///
/// Concrete implementation of NotificationRepository.
/// Coordinates between local datasource and domain layer.
library;
import 'package:worker/features/notifications/data/datasources/notification_local_datasource.dart';
import 'package:worker/features/notifications/data/models/notification_model.dart';
import 'package:worker/features/notifications/domain/entities/notification.dart';
import 'package:worker/features/notifications/domain/repositories/notification_repository.dart';
/// Notification Repository Implementation
class NotificationRepositoryImpl implements NotificationRepository {
/// Local data source
final NotificationLocalDataSource localDataSource;
/// Constructor
NotificationRepositoryImpl({required this.localDataSource});
@override
Future<List<Notification>> getAllNotifications() async {
final jsonList = await localDataSource.getAllNotifications();
return jsonList.map((json) => NotificationModel.fromJson(json)).toList()
..sort((a, b) => b.createdAt.compareTo(a.createdAt)); // Sort by newest first
}
@override
Future<List<Notification>> getNotificationsByCategory(String category) async {
final jsonList = await localDataSource.getNotificationsByCategory(category);
return jsonList.map((json) => NotificationModel.fromJson(json)).toList()
..sort((a, b) => b.createdAt.compareTo(a.createdAt));
}
@override
Future<int> getUnreadCount() async {
return await localDataSource.getUnreadCount();
}
@override
Future<void> markAsRead(String notificationId) async {
await localDataSource.markAsRead(notificationId);
}
@override
Future<void> markAllAsRead() async {
await localDataSource.markAllAsRead();
}
@override
Future<List<Notification>> refreshNotifications() async {
// For now, just fetch all notifications
// In production, this would fetch from server
return await getAllNotifications();
}
}

View File

@@ -100,6 +100,32 @@ class Notification {
return timeSinceCreated.inDays > 7;
}
/// Get formatted time ago text (Vietnamese)
String get formattedTimeAgo {
final duration = timeSinceCreated;
if (duration.inMinutes < 1) {
return 'Vừa xong';
} else if (duration.inMinutes < 60) {
return '${duration.inMinutes} phút trước';
} else if (duration.inHours < 24) {
return '${duration.inHours} giờ trước';
} else if (duration.inDays == 1) {
return 'Hôm qua';
} else if (duration.inDays < 7) {
return '${duration.inDays} ngày trước';
} else if (duration.inDays < 30) {
final weeks = (duration.inDays / 7).floor();
return '$weeks tuần trước';
} else if (duration.inDays < 365) {
final months = (duration.inDays / 30).floor();
return '$months tháng trước';
} else {
final years = (duration.inDays / 365).floor();
return '$years năm trước';
}
}
/// Copy with method for immutability
Notification copyWith({
String? notificationId,

View File

@@ -0,0 +1,32 @@
/// Notification Repository Interface
///
/// Defines operations for managing notifications.
library;
import 'package:worker/features/notifications/domain/entities/notification.dart';
/// Notification Repository
///
/// Provides methods to:
/// - Fetch notifications (all, by category, unread)
/// - Mark notifications as read
/// - Get notification counts
abstract class NotificationRepository {
/// Get all notifications
Future<List<Notification>> getAllNotifications();
/// Get notifications by category (general or order)
Future<List<Notification>> getNotificationsByCategory(String category);
/// Get unread notifications count
Future<int> getUnreadCount();
/// Mark notification as read
Future<void> markAsRead(String notificationId);
/// Mark all notifications as read
Future<void> markAllAsRead();
/// Refresh notifications (fetch from server)
Future<List<Notification>> refreshNotifications();
}

View File

@@ -0,0 +1,283 @@
/// Notifications Page
///
/// Displays user notifications with category tabs (General/Orders).
/// Features:
/// - Tab navigation for filtering notifications
/// - Unread notification indicators (blue left border)
/// - Pull-to-refresh
/// - Empty state when no notifications
library;
import 'package:flutter/material.dart' hide Notification;
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:worker/core/constants/ui_constants.dart';
import 'package:worker/core/theme/colors.dart';
import 'package:worker/features/notifications/domain/entities/notification.dart';
import 'package:worker/features/notifications/presentation/providers/notifications_provider.dart';
import 'package:worker/features/notifications/presentation/widgets/notification_card.dart';
/// Notifications Page
///
/// Main notifications screen accessible from bottom navigation.
class NotificationsPage extends HookConsumerWidget {
const NotificationsPage({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
// Use Flutter hooks for local state management
final selectedCategory = useState<String>('general');
final notificationsAsync = ref.watch(
filteredNotificationsProvider(selectedCategory.value),
);
return Scaffold(
backgroundColor: const Color(0xFFF4F6F8),
body: SafeArea(
child: Column(
children: [
// Header
_buildHeader(),
// Tabs
_buildTabs(context, selectedCategory),
// Notifications List
Expanded(
child: notificationsAsync.when(
data: (notifications) => _buildNotificationsList(
context,
ref,
notifications,
selectedCategory,
),
loading: () => const Center(child: CircularProgressIndicator()),
error: (error, stack) =>
_buildErrorState(ref, selectedCategory),
),
),
],
),
),
);
}
/// Build header
Widget _buildHeader() {
return Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.black.withValues(alpha: 0.05),
blurRadius: 8,
offset: const Offset(0, 2),
),
],
),
child: const Text(
'Thông báo',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Color(0xFF212121),
),
),
);
}
/// Build category tabs
Widget _buildTabs(
BuildContext context,
ValueNotifier<String> selectedCategory,
) {
return Container(
padding: const EdgeInsets.all(AppSpacing.md),
child: Row(
children: [
Expanded(
child: _buildTabButton(
context,
selectedCategory,
label: 'Chung',
category: 'general',
isSelected: selectedCategory.value == 'general',
),
),
const SizedBox(width: AppSpacing.sm),
Expanded(
child: _buildTabButton(
context,
selectedCategory,
label: 'Đơn hàng',
category: 'order',
isSelected: selectedCategory.value == 'order',
),
),
],
),
);
}
/// Build tab button
Widget _buildTabButton(
BuildContext context,
ValueNotifier<String> selectedCategory, {
required String label,
required String category,
required bool isSelected,
}) {
return ElevatedButton(
onPressed: () {
selectedCategory.value = category;
},
style: ElevatedButton.styleFrom(
backgroundColor: isSelected ? AppColors.primaryBlue : Colors.white,
foregroundColor: isSelected ? Colors.white : const Color(0xFF64748B),
elevation: 0,
padding: const EdgeInsets.symmetric(vertical: 12),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(AppRadius.button),
side: BorderSide(
color: isSelected ? AppColors.primaryBlue : const Color(0xFFE2E8F0),
width: 1,
),
),
),
child: Text(
label,
style: TextStyle(
fontSize: 14,
fontWeight: isSelected ? FontWeight.w600 : FontWeight.w500,
),
),
);
}
/// Build notifications list
Widget _buildNotificationsList(
BuildContext context,
WidgetRef ref,
List<Notification> notifications,
ValueNotifier<String> selectedCategory,
) {
if (notifications.isEmpty) {
return _buildEmptyState();
}
return RefreshIndicator(
onRefresh: () async {
ref.invalidate(filteredNotificationsProvider(selectedCategory.value));
},
child: ListView.builder(
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.md),
itemCount: notifications.length,
itemBuilder: (context, index) {
final notification = notifications[index];
return NotificationCard(
notification: notification,
onTap: () {
// TODO: Handle notification tap (mark as read, navigate to related entity)
_handleNotificationTap(context, ref, notification);
},
);
},
),
);
}
/// Build empty state
Widget _buildEmptyState() {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.notifications_none,
size: 64,
color: AppColors.grey500.withValues(alpha: 0.5),
),
const SizedBox(height: 16),
const Text(
'Không có thông báo',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: AppColors.grey500,
),
),
const SizedBox(height: 8),
const Text(
'Bạn chưa có thông báo nào',
style: TextStyle(fontSize: 14, color: AppColors.grey500),
),
],
),
);
}
/// Build error state
Widget _buildErrorState(
WidgetRef ref,
ValueNotifier<String> selectedCategory,
) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.error_outline,
size: 64,
color: AppColors.danger.withValues(alpha: 0.5),
),
const SizedBox(height: 16),
const Text(
'Không thể tải thông báo',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: AppColors.grey500,
),
),
const SizedBox(height: 16),
ElevatedButton.icon(
onPressed: () {
ref.invalidate(
filteredNotificationsProvider(selectedCategory.value),
);
},
icon: const Icon(Icons.refresh),
label: const Text('Thử lại'),
style: ElevatedButton.styleFrom(
backgroundColor: AppColors.primaryBlue,
foregroundColor: Colors.white,
),
),
],
),
);
}
/// Handle notification tap
void _handleNotificationTap(
BuildContext context,
WidgetRef ref,
Notification notification,
) {
// Mark as read if unread
if (notification.isUnread) {
// TODO: Implement mark as read
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Đã đánh dấu đã đọc'),
duration: Duration(seconds: 1),
),
);
}
// Navigate to related entity if exists
// TODO: Implement navigation based on notification type
}
}

View File

@@ -0,0 +1,42 @@
/// Notifications Providers
///
/// Riverpod providers for managing notification state.
library;
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:worker/features/notifications/data/datasources/notification_local_datasource.dart';
import 'package:worker/features/notifications/data/repositories/notification_repository_impl.dart';
import 'package:worker/features/notifications/domain/entities/notification.dart';
import 'package:worker/features/notifications/domain/repositories/notification_repository.dart';
/// Notification Local Data Source Provider
final notificationLocalDataSourceProvider =
Provider<NotificationLocalDataSource>((ref) {
return NotificationLocalDataSource();
});
/// Notification Repository Provider
final notificationRepositoryProvider = Provider<NotificationRepository>((ref) {
final localDataSource = ref.watch(notificationLocalDataSourceProvider);
return NotificationRepositoryImpl(localDataSource: localDataSource);
});
/// All Notifications Provider
final notificationsProvider = FutureProvider<List<Notification>>((ref) async {
final repository = ref.watch(notificationRepositoryProvider);
return await repository.getAllNotifications();
});
/// Filtered Notifications Provider (by category parameter)
/// Use .family to pass category as parameter from UI
final filteredNotificationsProvider =
FutureProvider.family<List<Notification>, String>((ref, category) async {
final repository = ref.watch(notificationRepositoryProvider);
return await repository.getNotificationsByCategory(category);
});
/// Unread Count Provider
final unreadNotificationCountProvider = FutureProvider<int>((ref) async {
final repository = ref.watch(notificationRepositoryProvider);
return await repository.getUnreadCount();
});

View File

@@ -0,0 +1,162 @@
/// Notification Card Widget
///
/// Displays a single notification item with icon, title, message, and timestamp.
/// Shows unread indicator with blue left border for unread notifications.
library;
import 'package:flutter/material.dart';
import 'package:worker/core/constants/ui_constants.dart';
import 'package:worker/core/theme/colors.dart';
import 'package:worker/features/notifications/domain/entities/notification.dart'
as entity;
/// Notification Card
///
/// Features:
/// - Icon with color based on notification type
/// - Title and message text
/// - Time ago timestamp
/// - Blue left border for unread notifications
/// - Tap handler
class NotificationCard extends StatelessWidget {
/// Notification to display
final entity.Notification notification;
/// Tap callback
final VoidCallback? onTap;
/// Constructor
const NotificationCard({super.key, required this.notification, this.onTap});
@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.only(bottom: 12),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12),
border: notification.isUnread
? const Border(
left: BorderSide(color: AppColors.primaryBlue, width: 3),
)
: null,
boxShadow: [
BoxShadow(
color: Colors.black.withValues(alpha: 0.05),
blurRadius: 8,
offset: const Offset(0, 2),
),
],
),
child: Material(
color: Colors.transparent,
child: InkWell(
onTap: onTap,
borderRadius: BorderRadius.circular(12),
child: Padding(
padding: const EdgeInsets.all(AppSpacing.md),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Title with icon
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Icon(_getIcon(), size: 18, color: _getIconColor()),
const SizedBox(width: 8),
Expanded(
child: Text(
notification.title,
style: TextStyle(
fontSize: 14,
fontWeight: notification.isUnread
? FontWeight.w600
: FontWeight.w500,
color: const Color(0xFF212121),
),
),
),
],
),
const SizedBox(height: 4),
// Message
Padding(
padding: const EdgeInsets.only(left: 26),
child: Text(
notification.message,
style: const TextStyle(
fontSize: 13,
color: Color(0xFF64748B),
),
),
),
const SizedBox(height: 8),
// Time ago
Padding(
padding: const EdgeInsets.only(left: 26),
child: Text(
notification.formattedTimeAgo,
style: const TextStyle(
fontSize: 11,
color: Color(0xFF94A3B8),
),
),
),
],
),
),
),
),
);
}
/// Get icon based on notification type
IconData _getIcon() {
final type = notification.type.toLowerCase();
if (type.contains('points') || type.contains('loyalty')) {
return Icons.card_giftcard;
} else if (type.contains('promotion') || type.contains('sale')) {
return Icons.local_offer;
} else if (type.contains('shipping')) {
return Icons.local_shipping;
} else if (type.contains('tier') || type.contains('upgrade')) {
return Icons.workspace_premium;
} else if (type.contains('event')) {
return Icons.event;
} else if (type.contains('confirmed')) {
return Icons.check_circle;
} else if (type.contains('birthday')) {
return Icons.cake;
} else {
return Icons.notifications;
}
}
/// Get icon color based on notification type
Color _getIconColor() {
final type = notification.type.toLowerCase();
if (type.contains('points') || type.contains('loyalty')) {
return AppColors.primaryBlue; // Blue for points/loyalty
} else if (type.contains('promotion') || type.contains('sale')) {
return AppColors.warning; // Orange/yellow for promotions
} else if (type.contains('shipping')) {
return AppColors.success; // Green for shipping
} else if (type.contains('tier') || type.contains('upgrade')) {
return AppColors.warning; // Gold/yellow for tier
} else if (type.contains('event')) {
return AppColors.primaryBlue; // Blue for events
} else if (type.contains('confirmed')) {
return AppColors.success; // Green for confirmations
} else if (type.contains('birthday')) {
return const Color(0xFFFF69B4); // Pink for birthday
} else {
return AppColors.grey500; // Gray for system
}
}
}