forked from eatvio/eatvio_app
feat(notifications): Issue-236
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import 'dart:developer';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:eatvio_app/features/menu/presentation/bloc/notification_settings_cubit/notification_settings_state.dart';
|
||||
import 'package:eatvio_app/features/menu/repositories/notification_settings_repository.dart';
|
||||
|
||||
class NotificationSettingsCubit extends Cubit<NotificationSettingsState> {
|
||||
final NotificationSettingsRepository _notificationSettingsRepository;
|
||||
|
||||
NotificationSettingsCubit({required NotificationSettingsRepository notificationSettingsRepository})
|
||||
: _notificationSettingsRepository = notificationSettingsRepository,
|
||||
super(const NotificationSettingsStateLoading());
|
||||
|
||||
Future<void> getNotificationSettings() async {
|
||||
emit(const NotificationSettingsStateLoading());
|
||||
try {
|
||||
final notificationSettings = await _notificationSettingsRepository.getNotificationSettings();
|
||||
emit(NotificationSettingsStateLoaded(notificationSettings: notificationSettings));
|
||||
} catch (e, stackTrace) {
|
||||
log('Error getting notification settings: $e', stackTrace: stackTrace);
|
||||
emit(NotificationSettingsStateError(errorMessage: e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> updateNotificationSettings(Map<String, dynamic> data) async {
|
||||
try {
|
||||
final notificationSettings = await _notificationSettingsRepository.updateNotificationSettings(data);
|
||||
emit(NotificationSettingsStateLoaded(notificationSettings: notificationSettings));
|
||||
} catch (e, stackTrace) {
|
||||
log('Error updating notification settings: $e', stackTrace: stackTrace);
|
||||
emit(NotificationSettingsStateError(errorMessage: e.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:eatvio_app/features/menu/models/notification_settings_model.dart';
|
||||
|
||||
abstract class NotificationSettingsState extends Equatable {
|
||||
const NotificationSettingsState();
|
||||
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
class NotificationSettingsStateLoading extends NotificationSettingsState {
|
||||
const NotificationSettingsStateLoading();
|
||||
}
|
||||
|
||||
class NotificationSettingsStateLoaded extends NotificationSettingsState {
|
||||
final NotificationSettingsModel notificationSettings;
|
||||
|
||||
const NotificationSettingsStateLoaded({required this.notificationSettings});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [notificationSettings];
|
||||
}
|
||||
|
||||
class NotificationSettingsStateError extends NotificationSettingsState {
|
||||
final String errorMessage;
|
||||
|
||||
const NotificationSettingsStateError({required this.errorMessage});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [errorMessage];
|
||||
}
|
||||
Reference in New Issue
Block a user