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

76 lines
2.3 KiB
Dart
Raw Normal View History

2023-08-04 21:11:41 +02:00
part of '../viewer_settings.dart';
@npLog
2024-06-17 18:04:53 +02:00
class _Bloc extends Bloc<_Event, _State>
with BlocLogger, BlocForEachMixin<_Event, _State> {
2023-08-04 21:11:41 +02:00
_Bloc({
required this.prefController,
}) : super(_State(
screenBrightness: prefController.viewerScreenBrightnessValue,
isForceRotation: prefController.isViewerForceRotationValue,
gpsMapProvider: prefController.gpsMapProviderValue,
2023-08-04 21:11:41 +02:00
)) {
on<_Init>(_onInit);
on<_SetScreenBrightness>(_onSetScreenBrightness);
on<_SetForceRotation>(_onSetForceRotation);
on<_SetGpsMapProvider>(_onSetGpsMapProvider);
}
@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.viewerScreenBrightnessChange,
2023-08-04 21:11:41 +02:00
onData: (data) => state.copyWith(screenBrightness: 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.isViewerForceRotationChange,
2023-08-04 21:11:41 +02:00
onData: (data) => state.copyWith(isForceRotation: 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.gpsMapProviderChange,
2023-08-04 21:11:41 +02:00
onData: (data) => state.copyWith(gpsMapProvider: data),
onError: (e, stackTrace) {
_log.severe("[_onInit] Uncaught exception", e, stackTrace);
return state.copyWith(error: ExceptionEvent(e, stackTrace));
},
),
]);
}
void _onSetScreenBrightness(_SetScreenBrightness ev, Emitter<_State> emit) {
_log.info(ev);
if (ev.value < 0) {
prefController.setViewerScreenBrightness(-1);
} else {
prefController.setViewerScreenBrightness((ev.value * 100).round());
}
}
void _onSetForceRotation(_SetForceRotation ev, Emitter<_State> emit) {
_log.info(ev);
prefController.setViewerForceRotation(ev.value);
}
void _onSetGpsMapProvider(_SetGpsMapProvider ev, Emitter<_State> emit) {
_log.info(ev);
prefController.setGpsMapProvider(ev.value);
}
final PrefController prefController;
}