feat: Refactor code structure and optimize performance across multiple modules
This commit is contained in:
@@ -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,
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
part of 'notifications_bloc.dart';
|
||||
|
||||
@immutable
|
||||
sealed class NotificationsEvent {}
|
||||
|
||||
class NotificationsInitEvent extends NotificationsEvent {
|
||||
}
|
||||
@@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user