You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
2.3 KiB
Dart
53 lines
2.3 KiB
Dart
import 'dart:developer';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:test_sa/controllers/notification/firebase_notification_manger.dart';
|
|
import 'package:test_sa/controllers/providers/api/notifications_provider.dart';
|
|
import 'package:test_sa/extensions/context_extension.dart';
|
|
import 'package:test_sa/extensions/widget_extensions.dart';
|
|
import 'package:test_sa/models/system_notification_model.dart';
|
|
import 'package:test_sa/views/pages/user/notifications/widgets/notification_card_redesigned.dart';
|
|
import 'package:test_sa/views/widgets/loaders/lazy_loading.dart';
|
|
import 'package:test_sa/views/widgets/loaders/no_data_found.dart';
|
|
|
|
class NotificationsList extends StatelessWidget {
|
|
final List<SystemNotificationModel> notifications;
|
|
final bool nextPage;
|
|
final Future<void> Function() onLazyLoad;
|
|
|
|
const NotificationsList({Key? key, this.notifications = const <SystemNotificationModel>[], required this.nextPage, required this.onLazyLoad}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (notifications.isEmpty) {
|
|
return NoDataFound(message: context.translation.notificationsNotFound).center;
|
|
}
|
|
return LazyLoading(
|
|
nextPage: nextPage,
|
|
onLazyLoad: onLazyLoad,
|
|
child: ListView.separated(
|
|
// padding: const EdgeInsets.all(16),
|
|
itemCount: notifications.length,
|
|
separatorBuilder: (context, itemIndex) => const SizedBox(height: 12),
|
|
itemBuilder: (context, itemIndex) {
|
|
final notification = notifications[itemIndex];
|
|
return NotificationCardRedesigned(
|
|
notification: notification,
|
|
onTap: () async {
|
|
// Mark notification as read when tapped
|
|
log('i am tapped with id ${notification.toJson()}');
|
|
if (notification.id != null && !(notification.readed ?? false)) {
|
|
final provider = Provider.of<NotificationsProvider>(context, listen: false);
|
|
await provider.markOneAsRead(notificationId: notification.id!);
|
|
}
|
|
|
|
// Navigate to notification details
|
|
FirebaseNotificationManger.handleMessage(context, notification.toNotificationJson());
|
|
},
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
} |