feat: Implement notifications feature, enhance profile settings with new sections, and integrate Firebase configurations for multiple environments.
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
class AppNotification {
|
||||
final String id;
|
||||
final String userId;
|
||||
final String type; // 'connection' | 'message' | 'system' | 'update' | 'request'
|
||||
final String title;
|
||||
final String description;
|
||||
final bool read;
|
||||
final String? actionUrl;
|
||||
final Map<String, String>? data;
|
||||
final DateTime createdAt;
|
||||
|
||||
const AppNotification({
|
||||
required this.id,
|
||||
required this.userId,
|
||||
required this.type,
|
||||
required this.title,
|
||||
required this.description,
|
||||
required this.read,
|
||||
this.actionUrl,
|
||||
this.data,
|
||||
required this.createdAt,
|
||||
});
|
||||
|
||||
factory AppNotification.fromJson(Map<String, dynamic> json) {
|
||||
return AppNotification(
|
||||
id: json['id'] as String,
|
||||
userId: json['userId'] as String? ?? '',
|
||||
type: json['type'] as String? ?? 'system',
|
||||
title: json['title'] as String? ?? '',
|
||||
description: json['description'] as String? ?? '',
|
||||
read: json['read'] as bool? ?? false,
|
||||
actionUrl: json['actionUrl'] as String?,
|
||||
data: json['data'] != null
|
||||
? Map<String, String>.from(json['data'] as Map)
|
||||
: null,
|
||||
createdAt: DateTime.parse(json['createdAt'] as String),
|
||||
);
|
||||
}
|
||||
|
||||
AppNotification copyWith({bool? read}) {
|
||||
return AppNotification(
|
||||
id: id,
|
||||
userId: userId,
|
||||
type: type,
|
||||
title: title,
|
||||
description: description,
|
||||
read: read ?? this.read,
|
||||
actionUrl: actionUrl,
|
||||
data: data,
|
||||
createdAt: createdAt,
|
||||
);
|
||||
}
|
||||
}
|
||||
103
lib/features/notifications/data/notification_repository.dart
Normal file
103
lib/features/notifications/data/notification_repository.dart
Normal file
@@ -0,0 +1,103 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:real_estate_mobile/core/network/api_client.dart';
|
||||
import 'package:real_estate_mobile/core/network/api_exceptions.dart';
|
||||
import 'package:real_estate_mobile/features/notifications/data/models/notification_model.dart';
|
||||
|
||||
class NotificationRepository {
|
||||
final Dio _dio = ApiClient.instance.dio;
|
||||
|
||||
/// Fetch notifications with optional filter and pagination.
|
||||
/// GET /notifications?filter=all|unread&page=1&limit=20
|
||||
Future<NotificationsResponse> getNotifications({
|
||||
String filter = 'all',
|
||||
int page = 1,
|
||||
int limit = 20,
|
||||
}) async {
|
||||
try {
|
||||
final response = await _dio.get('/notifications', queryParameters: {
|
||||
'filter': filter,
|
||||
'page': page,
|
||||
'limit': limit,
|
||||
});
|
||||
final data = response.data['data'] as Map<String, dynamic>;
|
||||
return NotificationsResponse.fromJson(data);
|
||||
} on DioException catch (e) {
|
||||
if (e.error is ApiException) throw e.error as ApiException;
|
||||
throw ApiException(
|
||||
message: e.message ?? 'Failed to fetch notifications',
|
||||
statusCode: e.response?.statusCode,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Get unread notification count.
|
||||
/// GET /notifications/unread-count
|
||||
Future<int> getUnreadCount() async {
|
||||
try {
|
||||
final response = await _dio.get('/notifications/unread-count');
|
||||
final data = response.data['data'] as Map<String, dynamic>;
|
||||
return data['unreadCount'] as int? ?? 0;
|
||||
} on DioException catch (e) {
|
||||
if (e.error is ApiException) throw e.error as ApiException;
|
||||
throw ApiException(
|
||||
message: e.message ?? 'Failed to fetch unread count',
|
||||
statusCode: e.response?.statusCode,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Mark a single notification as read.
|
||||
/// PATCH /notifications/:id/read
|
||||
Future<void> markAsRead(String notificationId) async {
|
||||
try {
|
||||
await _dio.patch('/notifications/$notificationId/read');
|
||||
} on DioException catch (e) {
|
||||
if (e.error is ApiException) throw e.error as ApiException;
|
||||
throw ApiException(
|
||||
message: e.message ?? 'Failed to mark notification as read',
|
||||
statusCode: e.response?.statusCode,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Mark all notifications as read.
|
||||
/// PATCH /notifications/read-all
|
||||
Future<void> markAllAsRead() async {
|
||||
try {
|
||||
await _dio.patch('/notifications/read-all');
|
||||
} on DioException catch (e) {
|
||||
if (e.error is ApiException) throw e.error as ApiException;
|
||||
throw ApiException(
|
||||
message: e.message ?? 'Failed to mark all as read',
|
||||
statusCode: e.response?.statusCode,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class NotificationsResponse {
|
||||
final List<AppNotification> notifications;
|
||||
final int unreadCount;
|
||||
final int totalPages;
|
||||
final int currentPage;
|
||||
|
||||
const NotificationsResponse({
|
||||
required this.notifications,
|
||||
required this.unreadCount,
|
||||
required this.totalPages,
|
||||
required this.currentPage,
|
||||
});
|
||||
|
||||
factory NotificationsResponse.fromJson(Map<String, dynamic> json) {
|
||||
final list = (json['notifications'] as List<dynamic>?)
|
||||
?.map((e) => AppNotification.fromJson(e as Map<String, dynamic>))
|
||||
.toList() ??
|
||||
[];
|
||||
return NotificationsResponse(
|
||||
notifications: list,
|
||||
unreadCount: json['unreadCount'] as int? ?? 0,
|
||||
totalPages: json['totalPages'] as int? ?? 1,
|
||||
currentPage: json['currentPage'] as int? ?? 1,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:real_estate_mobile/features/notifications/data/models/notification_model.dart';
|
||||
import 'package:real_estate_mobile/features/notifications/data/notification_repository.dart';
|
||||
|
||||
/// Unread notification count — polled every 30 seconds.
|
||||
final unreadCountProvider =
|
||||
StateNotifierProvider<UnreadCountNotifier, int>((ref) {
|
||||
return UnreadCountNotifier(NotificationRepository());
|
||||
});
|
||||
|
||||
class UnreadCountNotifier extends StateNotifier<int> {
|
||||
final NotificationRepository _repo;
|
||||
Timer? _timer;
|
||||
|
||||
UnreadCountNotifier(this._repo) : super(0) {
|
||||
refresh();
|
||||
_timer = Timer.periodic(const Duration(seconds: 30), (_) => refresh());
|
||||
}
|
||||
|
||||
Future<void> refresh() async {
|
||||
try {
|
||||
final count = await _repo.getUnreadCount();
|
||||
if (mounted) state = count;
|
||||
} catch (_) {
|
||||
// Silently fail — badge just won't update
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_timer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// Notification list state.
|
||||
class NotificationListState {
|
||||
final List<AppNotification> notifications;
|
||||
final bool isLoading;
|
||||
final bool isLoadingMore;
|
||||
final String? error;
|
||||
final String filter; // 'all' | 'unread'
|
||||
final int currentPage;
|
||||
final int totalPages;
|
||||
|
||||
const NotificationListState({
|
||||
this.notifications = const [],
|
||||
this.isLoading = false,
|
||||
this.isLoadingMore = false,
|
||||
this.error,
|
||||
this.filter = 'all',
|
||||
this.currentPage = 1,
|
||||
this.totalPages = 1,
|
||||
});
|
||||
|
||||
NotificationListState copyWith({
|
||||
List<AppNotification>? notifications,
|
||||
bool? isLoading,
|
||||
bool? isLoadingMore,
|
||||
String? error,
|
||||
String? filter,
|
||||
int? currentPage,
|
||||
int? totalPages,
|
||||
}) {
|
||||
return NotificationListState(
|
||||
notifications: notifications ?? this.notifications,
|
||||
isLoading: isLoading ?? this.isLoading,
|
||||
isLoadingMore: isLoadingMore ?? this.isLoadingMore,
|
||||
error: error,
|
||||
filter: filter ?? this.filter,
|
||||
currentPage: currentPage ?? this.currentPage,
|
||||
totalPages: totalPages ?? this.totalPages,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
final notificationListProvider =
|
||||
StateNotifierProvider<NotificationListNotifier, NotificationListState>(
|
||||
(ref) {
|
||||
return NotificationListNotifier(NotificationRepository(), ref);
|
||||
});
|
||||
|
||||
class NotificationListNotifier extends StateNotifier<NotificationListState> {
|
||||
final NotificationRepository _repo;
|
||||
final Ref _ref;
|
||||
|
||||
NotificationListNotifier(this._repo, this._ref)
|
||||
: super(const NotificationListState());
|
||||
|
||||
Future<void> loadNotifications({String filter = 'all'}) async {
|
||||
state = state.copyWith(isLoading: true, error: null, filter: filter);
|
||||
try {
|
||||
final response =
|
||||
await _repo.getNotifications(filter: filter, page: 1, limit: 20);
|
||||
state = state.copyWith(
|
||||
notifications: response.notifications,
|
||||
isLoading: false,
|
||||
currentPage: response.currentPage,
|
||||
totalPages: response.totalPages,
|
||||
);
|
||||
} catch (e) {
|
||||
state = state.copyWith(isLoading: false, error: e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> loadMore() async {
|
||||
if (state.isLoadingMore || state.currentPage >= state.totalPages) return;
|
||||
|
||||
state = state.copyWith(isLoadingMore: true);
|
||||
try {
|
||||
final nextPage = state.currentPage + 1;
|
||||
final response = await _repo.getNotifications(
|
||||
filter: state.filter, page: nextPage, limit: 20);
|
||||
state = state.copyWith(
|
||||
notifications: [...state.notifications, ...response.notifications],
|
||||
isLoadingMore: false,
|
||||
currentPage: response.currentPage,
|
||||
totalPages: response.totalPages,
|
||||
);
|
||||
} catch (_) {
|
||||
state = state.copyWith(isLoadingMore: false);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> markAsRead(String notificationId) async {
|
||||
try {
|
||||
await _repo.markAsRead(notificationId);
|
||||
state = state.copyWith(
|
||||
notifications: state.notifications.map((n) {
|
||||
if (n.id == notificationId) return n.copyWith(read: true);
|
||||
return n;
|
||||
}).toList(),
|
||||
);
|
||||
_ref.read(unreadCountProvider.notifier).refresh();
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
Future<void> markAllAsRead() async {
|
||||
try {
|
||||
await _repo.markAllAsRead();
|
||||
state = state.copyWith(
|
||||
notifications:
|
||||
state.notifications.map((n) => n.copyWith(read: true)).toList(),
|
||||
);
|
||||
_ref.read(unreadCountProvider.notifier).refresh();
|
||||
} catch (_) {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,401 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:real_estate_mobile/core/constants/app_colors.dart';
|
||||
import 'package:real_estate_mobile/features/notifications/data/models/notification_model.dart';
|
||||
import 'package:real_estate_mobile/features/notifications/presentation/providers/notification_provider.dart';
|
||||
|
||||
class NotificationsScreen extends ConsumerStatefulWidget {
|
||||
const NotificationsScreen({super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<NotificationsScreen> createState() =>
|
||||
_NotificationsScreenState();
|
||||
}
|
||||
|
||||
class _NotificationsScreenState extends ConsumerState<NotificationsScreen> {
|
||||
final ScrollController _scrollController = ScrollController();
|
||||
String _activeFilter = 'all';
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
Future.microtask(() {
|
||||
ref.read(notificationListProvider.notifier).loadNotifications();
|
||||
});
|
||||
_scrollController.addListener(_onScroll);
|
||||
}
|
||||
|
||||
void _onScroll() {
|
||||
if (_scrollController.position.pixels >=
|
||||
_scrollController.position.maxScrollExtent - 200) {
|
||||
ref.read(notificationListProvider.notifier).loadMore();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_scrollController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final state = ref.watch(notificationListProvider);
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
// ── Header bar matching Figma: "Notifications" with bell icon ──
|
||||
Container(
|
||||
height: 55,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(7),
|
||||
border: Border.all(
|
||||
color: AppColors.primaryDark.withValues(alpha: 0.1),
|
||||
width: 0.1,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.notifications,
|
||||
color: AppColors.accentOrange,
|
||||
size: 22,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
const Text(
|
||||
'Notifications',
|
||||
style: TextStyle(
|
||||
fontFamily: 'Fractul',
|
||||
fontSize: 17,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: AppColors.primaryDark,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// ── Filter tabs + Mark all as read ──
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||
child: Row(
|
||||
children: [
|
||||
_buildFilterChip('All', 'all'),
|
||||
const SizedBox(width: 8),
|
||||
_buildFilterChip('Unread', 'unread'),
|
||||
const Spacer(),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
ref
|
||||
.read(notificationListProvider.notifier)
|
||||
.markAllAsRead();
|
||||
},
|
||||
child: const Text(
|
||||
'Mark all as read',
|
||||
style: TextStyle(
|
||||
fontFamily: 'SourceSerif4',
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w400,
|
||||
color: AppColors.accentOrange,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// ── Notification list ──
|
||||
Expanded(
|
||||
child: _buildContent(state),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildFilterChip(String label, String filter) {
|
||||
final isActive = _activeFilter == filter;
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
setState(() => _activeFilter = filter);
|
||||
ref
|
||||
.read(notificationListProvider.notifier)
|
||||
.loadNotifications(filter: filter);
|
||||
},
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: isActive ? AppColors.primaryDark : Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
border: Border.all(
|
||||
color: isActive
|
||||
? AppColors.primaryDark
|
||||
: AppColors.primaryDark.withValues(alpha: 0.2),
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontFamily: 'Fractul',
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: isActive ? Colors.white : AppColors.primaryDark,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildContent(NotificationListState state) {
|
||||
if (state.isLoading) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(
|
||||
color: AppColors.accentOrange,
|
||||
strokeWidth: 2,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (state.error != null) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(Icons.error_outline,
|
||||
size: 48, color: AppColors.accentOrange),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Failed to load notifications',
|
||||
style: const TextStyle(
|
||||
fontFamily: 'Fractul',
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.primaryDark,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
ref
|
||||
.read(notificationListProvider.notifier)
|
||||
.loadNotifications(filter: _activeFilter);
|
||||
},
|
||||
child: const Text('Retry',
|
||||
style: TextStyle(color: AppColors.accentOrange)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (state.notifications.isEmpty) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.notifications_off_outlined,
|
||||
size: 48,
|
||||
color: AppColors.primaryDark.withValues(alpha: 0.3)),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
_activeFilter == 'unread'
|
||||
? 'No unread notifications'
|
||||
: 'No notifications yet',
|
||||
style: TextStyle(
|
||||
fontFamily: 'Fractul',
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.primaryDark.withValues(alpha: 0.5),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return ListView.builder(
|
||||
controller: _scrollController,
|
||||
padding: EdgeInsets.zero,
|
||||
itemCount: state.notifications.length + (state.isLoadingMore ? 1 : 0),
|
||||
itemBuilder: (context, index) {
|
||||
if (index == state.notifications.length) {
|
||||
return const Padding(
|
||||
padding: EdgeInsets.all(16),
|
||||
child: Center(
|
||||
child: CircularProgressIndicator(
|
||||
color: AppColors.accentOrange,
|
||||
strokeWidth: 2,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return _buildNotificationTile(state.notifications[index]);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildNotificationTile(AppNotification notification) {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
if (!notification.read) {
|
||||
ref
|
||||
.read(notificationListProvider.notifier)
|
||||
.markAsRead(notification.id);
|
||||
}
|
||||
},
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 12, vertical: 14),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// ── Avatar with unread dot ──
|
||||
SizedBox(
|
||||
width: 53,
|
||||
height: 52,
|
||||
child: Stack(
|
||||
children: [
|
||||
Container(
|
||||
width: 52,
|
||||
height: 52,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: _iconBgColor(notification.type),
|
||||
),
|
||||
child: Center(
|
||||
child: Icon(
|
||||
_iconForType(notification.type),
|
||||
color: AppColors.primaryDark,
|
||||
size: 24,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (!notification.read)
|
||||
Positioned(
|
||||
right: 0,
|
||||
bottom: 4,
|
||||
child: Container(
|
||||
width: 8,
|
||||
height: 8,
|
||||
decoration: const BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: AppColors.accentOrange,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
|
||||
// ── Title + Description ──
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
notification.title,
|
||||
style: TextStyle(
|
||||
fontFamily: 'Fractul',
|
||||
fontSize: 14,
|
||||
fontWeight:
|
||||
notification.read ? FontWeight.w500 : FontWeight.w700,
|
||||
color: AppColors.primaryDark,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
notification.description,
|
||||
style: TextStyle(
|
||||
fontFamily: 'SourceSerif4',
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w400,
|
||||
color: AppColors.primaryDark
|
||||
.withValues(alpha: notification.read ? 0.5 : 0.8),
|
||||
),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
|
||||
// ── Time ago ──
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 2),
|
||||
child: Text(
|
||||
_timeAgo(notification.createdAt),
|
||||
style: TextStyle(
|
||||
fontFamily: 'SourceSerif4',
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w400,
|
||||
color:
|
||||
AppColors.primaryDark.withValues(alpha: 0.6),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Divider(
|
||||
height: 0.1,
|
||||
thickness: 0.1,
|
||||
color: AppColors.primaryDark.withValues(alpha: 0.1),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
IconData _iconForType(String type) {
|
||||
switch (type) {
|
||||
case 'connection':
|
||||
return Icons.person_outline;
|
||||
case 'message':
|
||||
return Icons.chat_bubble_outline;
|
||||
case 'request':
|
||||
return Icons.assignment_outlined;
|
||||
case 'update':
|
||||
return Icons.notifications_outlined;
|
||||
case 'system':
|
||||
return Icons.settings_outlined;
|
||||
default:
|
||||
return Icons.notifications_outlined;
|
||||
}
|
||||
}
|
||||
|
||||
Color _iconBgColor(String type) {
|
||||
switch (type) {
|
||||
case 'connection':
|
||||
return const Color(0xFFE8F5E9);
|
||||
case 'message':
|
||||
return const Color(0xFFE3F2FD);
|
||||
case 'request':
|
||||
return const Color(0xFFFFF3E0);
|
||||
case 'update':
|
||||
return const Color(0xFFF3E5F5);
|
||||
case 'system':
|
||||
return const Color(0xFFF5F5F5);
|
||||
default:
|
||||
return const Color(0xFFF5F5F5);
|
||||
}
|
||||
}
|
||||
|
||||
String _timeAgo(DateTime dateTime) {
|
||||
final now = DateTime.now();
|
||||
final diff = now.difference(dateTime);
|
||||
|
||||
if (diff.inSeconds < 60) return 'Just now';
|
||||
if (diff.inMinutes < 60) return '${diff.inMinutes}m ago';
|
||||
if (diff.inHours < 24) return '${diff.inHours}hr ago';
|
||||
if (diff.inDays < 7) return '${diff.inDays}d ago';
|
||||
if (diff.inDays < 30) return '${(diff.inDays / 7).floor()}w ago';
|
||||
return '${(diff.inDays / 30).floor()}mo ago';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user