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

52 lines
1.5 KiB
Dart
Raw Normal View History

2023-08-09 16:45:32 +02:00
part of '../misc_settings.dart';
@npLog
2024-06-17 18:04:53 +02:00
class _Bloc extends Bloc<_Event, _State>
with BlocLogger, BlocForEachMixin<_Event, _State> {
2023-08-09 16:45:32 +02:00
_Bloc({
required this.prefController,
2024-05-26 13:09:16 +02:00
required this.securePrefController,
2023-08-09 16:45:32 +02:00
}) : super(_State(
isDoubleTapExit: prefController.isDoubleTapExitValue,
2024-05-26 13:09:16 +02:00
appLockType: securePrefController.protectedPageAuthTypeValue,
2023-08-09 16:45:32 +02:00
)) {
on<_Init>(_onInit);
on<_SetDoubleTapExit>(_onSetDoubleTapExit);
}
@override
String get tag => _log.fullName;
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,
prefController.isDoubleTapExitChange,
2023-08-09 16:45:32 +02:00
onData: (data) => state.copyWith(isDoubleTapExit: 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,
2024-05-26 13:09:16 +02:00
securePrefController.protectedPageAuthTypeChange,
onData: (data) => state.copyWith(appLockType: data),
onError: (e, stackTrace) {
_log.severe("[_onInit] Uncaught exception", e, stackTrace);
return state.copyWith(error: ExceptionEvent(e, stackTrace));
},
),
2023-08-09 16:45:32 +02:00
]);
}
void _onSetDoubleTapExit(_SetDoubleTapExit ev, Emitter<_State> emit) {
_log.info(ev);
prefController.setDoubleTapExit(ev.value);
}
final PrefController prefController;
2024-05-26 13:09:16 +02:00
final SecurePrefController securePrefController;
2023-08-09 16:45:32 +02:00
}