|
|
|
|
@ -10,11 +10,13 @@ import 'package:test_sa/extensions/widget_extensions.dart';
|
|
|
|
|
import 'package:test_sa/models/notification_filter_model.dart';
|
|
|
|
|
import 'package:test_sa/models/system_notification_model.dart';
|
|
|
|
|
import 'package:test_sa/new_views/app_style/app_color.dart';
|
|
|
|
|
import 'package:test_sa/new_views/common_widgets/app_lazy_loading.dart';
|
|
|
|
|
import 'package:test_sa/new_views/common_widgets/app_text_form_field.dart';
|
|
|
|
|
import 'package:test_sa/new_views/common_widgets/default_app_bar.dart';
|
|
|
|
|
import 'package:test_sa/views/pages/user/notifications/notification_filter_page.dart';
|
|
|
|
|
import 'package:test_sa/views/pages/user/notifications/notifications_list.dart';
|
|
|
|
|
import 'package:test_sa/views/pages/user/notifications/widgets/notification_tab_button.dart';
|
|
|
|
|
import 'package:test_sa/views/widgets/loaders/app_loading.dart';
|
|
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
|
|
import '../../../widgets/loaders/loading_manager.dart';
|
|
|
|
|
@ -108,15 +110,15 @@ class _NotificationsPageState extends State<NotificationsPage> with TickerProvid
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int get _unreadCount {
|
|
|
|
|
return _notificationsProvider.notifications.where((n) => !(n.readed ?? false)).length;
|
|
|
|
|
return _notificationsProvider.totalNotificationUnread;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int get _allCount {
|
|
|
|
|
return _notificationsProvider.notifications.length;
|
|
|
|
|
return _notificationsProvider.totalAllNotifications;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int get _readCount {
|
|
|
|
|
return _notificationsProvider.notifications.where((n) => n.readed ?? false).length;
|
|
|
|
|
return _notificationsProvider.totalNotificationRead;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Get count of active filters
|
|
|
|
|
@ -125,8 +127,6 @@ class _NotificationsPageState extends State<NotificationsPage> with TickerProvid
|
|
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
|
if (_activeFilters!.priorityIds?.isNotEmpty ?? false) count++;
|
|
|
|
|
if (_activeFilters!.channelIds?.isNotEmpty ?? false) count++;
|
|
|
|
|
if (_activeFilters!.recipientIds?.isNotEmpty ?? false) count++;
|
|
|
|
|
if (_activeFilters!.moduleIds?.isNotEmpty ?? false) count++;
|
|
|
|
|
if (_activeFilters!.subModuleIds?.isNotEmpty ?? false) count++;
|
|
|
|
|
if (_activeFilters!.startDate != null) count++;
|
|
|
|
|
@ -145,34 +145,26 @@ class _NotificationsPageState extends State<NotificationsPage> with TickerProvid
|
|
|
|
|
appBar: DefaultAppBar(
|
|
|
|
|
title: context.translation.notifications,
|
|
|
|
|
actions: [
|
|
|
|
|
// Mark All As Read Button
|
|
|
|
|
TextButton.icon(
|
|
|
|
|
onPressed: () async {
|
|
|
|
|
// Show loading dialog
|
|
|
|
|
showDialog(
|
|
|
|
|
context: context,
|
|
|
|
|
barrierDismissible: false,
|
|
|
|
|
builder: (context) => const Center(
|
|
|
|
|
child: CircularProgressIndicator(),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Call mark all as read API
|
|
|
|
|
final result = await _notificationsProvider.markAllAsRead(
|
|
|
|
|
userId: _userProvider.user!.userID!,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Close loading dialog
|
|
|
|
|
if (context.mounted) {
|
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Show API response message only if provided
|
|
|
|
|
if (context.mounted && result['message'] != null) {
|
|
|
|
|
result['message'].addTranslation.showToast;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
icon: 'Icon_mark_read'.toSvgAsset(width: 12, height: 12),
|
|
|
|
|
onPressed: _unreadCount > 0
|
|
|
|
|
? () async {
|
|
|
|
|
showDialog(context: context, barrierDismissible: false, builder: (context) => const AppLazyLoading());
|
|
|
|
|
final result = await _notificationsProvider.markAllAsRead(
|
|
|
|
|
userId: _userProvider.user!.userID!,
|
|
|
|
|
);
|
|
|
|
|
if (context.mounted) {
|
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
|
}
|
|
|
|
|
if (context.mounted && result['message'] != null) {
|
|
|
|
|
'${result['message']}'.showToast;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
: null,
|
|
|
|
|
icon: 'Icon_mark_read'.toSvgAsset(
|
|
|
|
|
width: 12,
|
|
|
|
|
height: 12,
|
|
|
|
|
color: AppColor.primary10,
|
|
|
|
|
),
|
|
|
|
|
label: Text(
|
|
|
|
|
'Mark All as Read',
|
|
|
|
|
style: AppTextStyles.bodyText2.copyWith(
|
|
|
|
|
@ -182,7 +174,7 @@ class _NotificationsPageState extends State<NotificationsPage> with TickerProvid
|
|
|
|
|
),
|
|
|
|
|
style: TextButton.styleFrom(
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
|
|
|
|
foregroundColor: AppColor.primary10,
|
|
|
|
|
foregroundColor: _unreadCount > 0 ? AppColor.primary10 : AppColor.neutral30,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
@ -214,17 +206,6 @@ class _NotificationsPageState extends State<NotificationsPage> with TickerProvid
|
|
|
|
|
|
|
|
|
|
16.height,
|
|
|
|
|
|
|
|
|
|
// Filter Section (Placeholder for future filter/sort buttons)
|
|
|
|
|
Container(
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
|
|
|
child: Row(
|
|
|
|
|
children: [
|
|
|
|
|
// TODO: Add Filter and Sort buttons here when needed
|
|
|
|
|
const Spacer(),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
// Notification Tabs
|
|
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
@ -310,7 +291,7 @@ class _NotificationsPageState extends State<NotificationsPage> with TickerProvid
|
|
|
|
|
if (_activeFilterCount > 0)
|
|
|
|
|
Positioned(
|
|
|
|
|
right: -8,
|
|
|
|
|
top: -8,
|
|
|
|
|
top: -12,
|
|
|
|
|
child: Container(
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 2),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
@ -347,7 +328,8 @@ class _NotificationsPageState extends State<NotificationsPage> with TickerProvid
|
|
|
|
|
Expanded(
|
|
|
|
|
child: LoadingManager(
|
|
|
|
|
isLoading: (_notificationsProvider.isLoading) && _notificationsProvider.notifications.isEmpty,
|
|
|
|
|
isFailedLoading: false, // Don't show error state, show no data found instead
|
|
|
|
|
isFailedLoading: false,
|
|
|
|
|
// Don't show error state, show no data found instead
|
|
|
|
|
stateCode: _notificationsProvider.stateCode,
|
|
|
|
|
onRefresh: () async {
|
|
|
|
|
_notificationsProvider.reset();
|
|
|
|
|
|