nc-photos/app/lib/widget/settings/photos/bloc.dart

58 lines
1.7 KiB
Dart
Raw Normal View History

2023-07-27 18:51:57 +02:00
part of '../photos_settings.dart';
@npLog
2024-06-17 18:04:53 +02:00
class _Bloc extends Bloc<_Event, _State>
with BlocLogger, BlocForEachMixin<_Event, _State> {
2023-07-27 18:51:57 +02:00
_Bloc({
required this.prefController,
required this.accountPrefController,
}) : super(_State(
isEnableMemories: accountPrefController.isEnableMemoryAlbumValue,
memoriesRange: prefController.memoriesRangeValue,
2023-07-27 18:51:57 +02:00
)) {
on<_Init>(_onInit);
on<_SetEnableMemories>(_onSetEnableMemories);
on<_SetMemoriesRange>(_onSetMemoriesRange);
}
2023-07-28 18:48:50 +02:00
@override
String get tag => _log.fullName;
2023-07-27 18:51:57 +02:00
Future<void> _onInit(_Init ev, Emitter<_State> emit) async {
_log.info(ev);
await Future.wait([
2024-06-17 18:04:53 +02:00
forEach(
emit,
accountPrefController.isEnableMemoryAlbumChange,
2023-07-27 18:51:57 +02:00
onData: (data) => state.copyWith(isEnableMemories: data),
onError: (e, stackTrace) {
_log.severe("[_onInit] Uncaught exception", e, stackTrace);
return state.copyWith(error: ExceptionEvent(e, stackTrace));
},
),
2024-06-17 18:04:53 +02:00
forEach(
emit,
prefController.memoriesRangeChange,
2023-07-27 18:51:57 +02:00
onData: (data) => state.copyWith(memoriesRange: data),
onError: (e, stackTrace) {
_log.severe("[_onInit] Uncaught exception", e, stackTrace);
return state.copyWith(error: ExceptionEvent(e, stackTrace));
},
),
]);
}
void _onSetEnableMemories(_SetEnableMemories ev, Emitter<_State> emit) {
_log.info(ev);
accountPrefController.setEnableMemoryAlbum(ev.value);
}
void _onSetMemoriesRange(_SetMemoriesRange ev, Emitter<_State> emit) {
_log.info(ev);
prefController.setMemoriesRange(ev.value);
}
final PrefController prefController;
final AccountPrefController accountPrefController;
}