diff --git a/lib/screens/metering/ev_source/camera/bloc_camera.dart b/lib/screens/metering/ev_source/camera/bloc_camera.dart index c651e4a..fefc0fd 100644 --- a/lib/screens/metering/ev_source/camera/bloc_camera.dart +++ b/lib/screens/metering/ev_source/camera/bloc_camera.dart @@ -44,6 +44,7 @@ class CameraBloc extends EvSourceBloc { on(_onInitialize); on(_onZoomChanged); on(_onExposureOffsetChanged); + on(_onExposureOffsetResetEvent); add(const InitializeEvent()); } @@ -119,10 +120,14 @@ class CameraBloc extends EvSourceBloc { Future _onExposureOffsetChanged(ExposureOffsetChangedEvent event, Emitter emit) async { _cameraController!.setExposureOffset(event.value); _currentExposureOffset = event.value; - if (event.value == 0.0) _meteringInteractor.quickVibration(); _emitActiveState(emit); } + Future _onExposureOffsetResetEvent(ExposureOffsetResetEvent event, Emitter emit) async { + _meteringInteractor.quickVibration(); + add(const ExposureOffsetChangedEvent(0)); + } + void _emitActiveState(Emitter emit) { emit(CameraActiveState( minZoom: _zoomRange!.start, diff --git a/lib/screens/metering/ev_source/camera/event_camera.dart b/lib/screens/metering/ev_source/camera/event_camera.dart index 0a30d07..96de582 100644 --- a/lib/screens/metering/ev_source/camera/event_camera.dart +++ b/lib/screens/metering/ev_source/camera/event_camera.dart @@ -17,3 +17,7 @@ class ExposureOffsetChangedEvent extends CameraEvent { const ExposureOffsetChangedEvent(this.value); } + +class ExposureOffsetResetEvent extends CameraEvent { + const ExposureOffsetResetEvent(); +} diff --git a/lib/screens/metering/screen_metering.dart b/lib/screens/metering/screen_metering.dart index 32d5d81..9a00b33 100644 --- a/lib/screens/metering/screen_metering.dart +++ b/lib/screens/metering/screen_metering.dart @@ -2,7 +2,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:lightmeter/data/models/photography_values/photography_value.dart'; import 'package:lightmeter/res/dimens.dart'; -import 'package:lightmeter/screens/settings/screen_settings.dart'; import 'components/bottom_controls/widget_bottom_controls.dart'; import 'components/camera/widget_exposure_slider.dart'; @@ -87,9 +86,7 @@ class _MeteringScreenState extends State { ), MeteringBottomControls( onMeasure: () => context.read().add(const MeasureEvent()), - onSettings: () { - Navigator.pushNamed(context, 'settings'); - }, + onSettings: () => Navigator.pushNamed(context, 'settings'), ), ], ), diff --git a/lib/screens/settings/components/calibration/bloc_list_tile_calibration.dart b/lib/screens/settings/components/calibration/bloc_list_tile_calibration.dart deleted file mode 100644 index e69de29..0000000 diff --git a/lib/screens/settings/components/calibration/components/calibration_dialog/bloc_dialog_calibration.dart b/lib/screens/settings/components/calibration/components/calibration_dialog/bloc_dialog_calibration.dart new file mode 100644 index 0000000..d14dd6c --- /dev/null +++ b/lib/screens/settings/components/calibration/components/calibration_dialog/bloc_dialog_calibration.dart @@ -0,0 +1,33 @@ +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:lightmeter/interactors/settings_interactor.dart'; + +import 'event_dialog_calibration.dart'; +import 'state_dialog_calibration.dart'; + +class CalibrationDialogBloc extends Bloc { + final SettingsInteractor _settingsInteractor; + + late double _cameraEvCalibration = _settingsInteractor.cameraEvCalibration; + + CalibrationDialogBloc(this._settingsInteractor) + : super(CalibrationDialogState(_settingsInteractor.cameraEvCalibration)) { + on(_onCameraEvCalibrationChanged); + on(_onCameraEvCalibrationReset); + on(_onSaveCalibration); + } + + void _onCameraEvCalibrationChanged(CameraEvCalibrationChangedEvent event, Emitter emit) { + _cameraEvCalibration = event.value; + emit(CalibrationDialogState(event.value)); + } + + void _onCameraEvCalibrationReset(CameraEvCalibrationResetEvent event, Emitter emit) { + _settingsInteractor.quickVibration(); + _cameraEvCalibration = _settingsInteractor.cameraEvCalibration; + emit(CalibrationDialogState(_cameraEvCalibration)); + } + + void _onSaveCalibration(SaveCalibrationDialogEvent event, __) { + _settingsInteractor.setCameraEvCalibration(_cameraEvCalibration); + } +} diff --git a/lib/screens/settings/components/calibration/components/calibration_dialog/event_dialog_calibration.dart b/lib/screens/settings/components/calibration/components/calibration_dialog/event_dialog_calibration.dart new file mode 100644 index 0000000..e949032 --- /dev/null +++ b/lib/screens/settings/components/calibration/components/calibration_dialog/event_dialog_calibration.dart @@ -0,0 +1,17 @@ +abstract class CalibrationDialogEvent { + const CalibrationDialogEvent(); +} + +class CameraEvCalibrationChangedEvent extends CalibrationDialogEvent { + final double value; + + const CameraEvCalibrationChangedEvent(this.value); +} + +class CameraEvCalibrationResetEvent extends CalibrationDialogEvent { + const CameraEvCalibrationResetEvent(); +} + +class SaveCalibrationDialogEvent extends CalibrationDialogEvent { + const SaveCalibrationDialogEvent(); +} diff --git a/lib/screens/settings/components/calibration/components/calibration_dialog/provider_dialog_calibration.dart b/lib/screens/settings/components/calibration/components/calibration_dialog/provider_dialog_calibration.dart new file mode 100644 index 0000000..1161265 --- /dev/null +++ b/lib/screens/settings/components/calibration/components/calibration_dialog/provider_dialog_calibration.dart @@ -0,0 +1,18 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:lightmeter/interactors/settings_interactor.dart'; + +import 'bloc_dialog_calibration.dart'; +import 'widget_dialog_calibration.dart'; + +class CalibrationDialogProvider extends StatelessWidget { + const CalibrationDialogProvider({super.key}); + + @override + Widget build(BuildContext context) { + return BlocProvider( + create: (context) => CalibrationDialogBloc(context.read()), + child: const CalibrationDialog(), + ); + } +} diff --git a/lib/screens/settings/components/calibration/components/calibration_dialog/state_dialog_calibration.dart b/lib/screens/settings/components/calibration/components/calibration_dialog/state_dialog_calibration.dart new file mode 100644 index 0000000..3561bcc --- /dev/null +++ b/lib/screens/settings/components/calibration/components/calibration_dialog/state_dialog_calibration.dart @@ -0,0 +1,5 @@ +class CalibrationDialogState { + final double cameraEvCalibration; + + const CalibrationDialogState(this.cameraEvCalibration); +} diff --git a/lib/screens/settings/components/calibration/components/calibration_dialog/widget_dialog_calibration.dart b/lib/screens/settings/components/calibration/components/calibration_dialog/widget_dialog_calibration.dart index 211f216..7d319fa 100644 --- a/lib/screens/settings/components/calibration/components/calibration_dialog/widget_dialog_calibration.dart +++ b/lib/screens/settings/components/calibration/components/calibration_dialog/widget_dialog_calibration.dart @@ -1,24 +1,22 @@ import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:lightmeter/generated/l10n.dart'; import 'package:lightmeter/res/dimens.dart'; +import 'package:lightmeter/screens/settings/components/calibration/components/calibration_dialog/event_dialog_calibration.dart'; import 'package:lightmeter/screens/shared/centered_slider/widget_slider_centered.dart'; import 'package:lightmeter/utils/to_string_signed.dart'; -class CalibrationDialog extends StatefulWidget { - final double cameraEvCalibration; +import 'bloc_dialog_calibration.dart'; +import 'state_dialog_calibration.dart'; - const CalibrationDialog({ - required this.cameraEvCalibration, - super.key, - }); +class CalibrationDialog extends StatefulWidget { + const CalibrationDialog({super.key}); @override State createState() => _CalibrationDialogState(); } class _CalibrationDialogState extends State { - late double _cameraEvCalibration = widget.cameraEvCalibration; - @override Widget build(BuildContext context) { return AlertDialog( @@ -30,21 +28,20 @@ class _CalibrationDialogState extends State { ), title: Text(S.of(context).calibration), contentPadding: const EdgeInsets.symmetric(horizontal: Dimens.paddingL), - content: Column( - mainAxisSize: MainAxisSize.min, - children: [ - Text(S.of(context).calibrationMessage), - const SizedBox(height: Dimens.grid16), - _CalibrationUnit( - title: S.of(context).camera, - value: _cameraEvCalibration, - onChanged: (value) { - setState(() { - _cameraEvCalibration = value; - }); - }, - ), - ], + content: BlocBuilder( + builder: (context, state) => Column( + mainAxisSize: MainAxisSize.min, + children: [ + Text(S.of(context).calibrationMessage), + const SizedBox(height: Dimens.grid16), + _CalibrationUnit( + title: S.of(context).camera, + value: state.cameraEvCalibration, + onChanged: (value) => context.read().add(CameraEvCalibrationChangedEvent(value)), + onReset: () => context.read().add(const CameraEvCalibrationResetEvent()), + ), + ], + ), ), actionsPadding: const EdgeInsets.fromLTRB( Dimens.paddingL, @@ -58,7 +55,10 @@ class _CalibrationDialogState extends State { child: Text(S.of(context).cancel), ), TextButton( - onPressed: () => Navigator.of(context).pop(_cameraEvCalibration), + onPressed: () { + context.read().add(const SaveCalibrationDialogEvent()); + Navigator.of(context).pop(); + }, child: Text(S.of(context).save), ), ], @@ -70,11 +70,13 @@ class _CalibrationUnit extends StatelessWidget { final String title; final double value; final ValueChanged onChanged; + final VoidCallback onReset; const _CalibrationUnit({ required this.title, required this.value, required this.onChanged, + required this.onReset, }); @override @@ -99,9 +101,7 @@ class _CalibrationUnit extends StatelessWidget { ), ), IconButton( - onPressed: () { - onChanged(0.0); - }, + onPressed: onReset, icon: const Icon(Icons.sync), ), ], diff --git a/lib/screens/settings/components/calibration/event_list_tile_calibration.dart b/lib/screens/settings/components/calibration/event_list_tile_calibration.dart deleted file mode 100644 index eec5ebd..0000000 --- a/lib/screens/settings/components/calibration/event_list_tile_calibration.dart +++ /dev/null @@ -1,9 +0,0 @@ -abstract class CalibrationEvent { - const CalibrationEvent(); -} - -class CameraEvCalibrationChangedEvent extends CalibrationEvent { - final double value; - - const CameraEvCalibrationChangedEvent(this.value); -} diff --git a/lib/screens/settings/components/calibration/widget_list_tile_calibration.dart b/lib/screens/settings/components/calibration/widget_list_tile_calibration.dart index 34bcf75..43de482 100644 --- a/lib/screens/settings/components/calibration/widget_list_tile_calibration.dart +++ b/lib/screens/settings/components/calibration/widget_list_tile_calibration.dart @@ -1,7 +1,9 @@ import 'package:flutter/material.dart'; import 'package:lightmeter/generated/l10n.dart'; +import 'package:lightmeter/interactors/settings_interactor.dart'; +import 'package:provider/provider.dart'; -import 'components/calibration_dialog/widget_dialog_calibration.dart'; +import 'components/calibration_dialog/provider_dialog_calibration.dart'; class CalibrationListTile extends StatelessWidget { const CalibrationListTile({super.key}); @@ -14,12 +16,11 @@ class CalibrationListTile extends StatelessWidget { onTap: () { showDialog( context: context, - builder: (_) => CalibrationDialog( - cameraEvCalibration: 0.0, + builder: (_) => Provider.value( + value: context.read(), + child: const CalibrationDialogProvider(), ), - ).then((value) { - if (value != null) {} - }); + ); }, ); } diff --git a/lib/screens/settings/flow_settings.dart b/lib/screens/settings/flow_settings.dart index 0c4cc63..9dcb803 100644 --- a/lib/screens/settings/flow_settings.dart +++ b/lib/screens/settings/flow_settings.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:lightmeter/data/haptics_service.dart'; import 'package:lightmeter/data/shared_prefs_service.dart'; import 'package:lightmeter/interactors/settings_interactor.dart';