feat: Refactor code structure and optimize performance across multiple modules

This commit is contained in:
Achintha Isuru
2025-11-17 23:29:28 -05:00
parent 831570f2e0
commit a64cbd9edf
1508 changed files with 105319 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
import 'package:bloc/bloc.dart';
import 'package:meta/meta.dart';
import '../../../../core/application/di/injectable.dart';
import '../notification_entity.dart';
import '../notification_repository.dart';
part 'notifications_event.dart';
part 'notifications_state.dart';
class NotificationsBloc extends Bloc<NotificationsEvent, NotificationsState> {
NotificationsBloc() : super(NotificationsState()) {
on<NotificationsInitEvent>(_onNotificationsInit);
}
void _onNotificationsInit(NotificationsInitEvent event, emit) async {
var notifications =
await getIt<NotificationsRepository>().fetchNotifications();
emit(state.copyWith(
notifications: notifications,
));
}
}

View File

@@ -0,0 +1,7 @@
part of 'notifications_bloc.dart';
@immutable
sealed class NotificationsEvent {}
class NotificationsInitEvent extends NotificationsEvent {
}

View File

@@ -0,0 +1,20 @@
part of 'notifications_bloc.dart';
@immutable
class NotificationsState {
final bool inLoading;
final List<NotificationEntity> notifications;
NotificationsState({this.inLoading = false, this.notifications = const []});
NotificationsState copyWith({
bool? inLoading,
List<NotificationEntity>? notifications,
}) {
return NotificationsState(
inLoading: inLoading ?? this.inLoading,
notifications: notifications ?? this.notifications,
);
}
}

View File

@@ -0,0 +1,41 @@
enum NotificationType {
general,
invoice,
event,
}
class NotificationEntity{
final String id;
final String title;
final String body;
final NotificationType type;
final DateTime dateTime;
final bool isRead;
NotificationEntity({
required this.title,
required this.body,
required this.dateTime,
required this.id,
required this.type,
this.isRead = false,
});
NotificationEntity copyWith({
String? id,
String? title,
String? body,
NotificationType? type,
DateTime? dateTime,
bool? isRead,
}) {
return NotificationEntity(
id: id ?? this.id,
title: title ?? this.title,
body: body ?? this.body,
type: type ?? this.type,
dateTime: dateTime ?? this.dateTime,
isRead: isRead ?? this.isRead,
);
}
}

View File

@@ -0,0 +1,6 @@
import 'notification_entity.dart';
abstract class NotificationsRepository {
Future<List<NotificationEntity>> fetchNotifications();
Future<void> readNotification(String id);
}