implemented CalibrationDialog

This commit is contained in:
Vadim 2023-01-25 22:25:50 +03:00
parent ab5b747831
commit dda0a38a0f
12 changed files with 118 additions and 48 deletions

View file

@ -44,6 +44,7 @@ class CameraBloc extends EvSourceBloc<CameraEvent, CameraState> {
on<InitializeEvent>(_onInitialize); on<InitializeEvent>(_onInitialize);
on<ZoomChangedEvent>(_onZoomChanged); on<ZoomChangedEvent>(_onZoomChanged);
on<ExposureOffsetChangedEvent>(_onExposureOffsetChanged); on<ExposureOffsetChangedEvent>(_onExposureOffsetChanged);
on<ExposureOffsetResetEvent>(_onExposureOffsetResetEvent);
add(const InitializeEvent()); add(const InitializeEvent());
} }
@ -119,10 +120,14 @@ class CameraBloc extends EvSourceBloc<CameraEvent, CameraState> {
Future<void> _onExposureOffsetChanged(ExposureOffsetChangedEvent event, Emitter emit) async { Future<void> _onExposureOffsetChanged(ExposureOffsetChangedEvent event, Emitter emit) async {
_cameraController!.setExposureOffset(event.value); _cameraController!.setExposureOffset(event.value);
_currentExposureOffset = event.value; _currentExposureOffset = event.value;
if (event.value == 0.0) _meteringInteractor.quickVibration();
_emitActiveState(emit); _emitActiveState(emit);
} }
Future<void> _onExposureOffsetResetEvent(ExposureOffsetResetEvent event, Emitter emit) async {
_meteringInteractor.quickVibration();
add(const ExposureOffsetChangedEvent(0));
}
void _emitActiveState(Emitter emit) { void _emitActiveState(Emitter emit) {
emit(CameraActiveState( emit(CameraActiveState(
minZoom: _zoomRange!.start, minZoom: _zoomRange!.start,

View file

@ -17,3 +17,7 @@ class ExposureOffsetChangedEvent extends CameraEvent {
const ExposureOffsetChangedEvent(this.value); const ExposureOffsetChangedEvent(this.value);
} }
class ExposureOffsetResetEvent extends CameraEvent {
const ExposureOffsetResetEvent();
}

View file

@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:lightmeter/data/models/photography_values/photography_value.dart'; import 'package:lightmeter/data/models/photography_values/photography_value.dart';
import 'package:lightmeter/res/dimens.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/bottom_controls/widget_bottom_controls.dart';
import 'components/camera/widget_exposure_slider.dart'; import 'components/camera/widget_exposure_slider.dart';
@ -87,9 +86,7 @@ class _MeteringScreenState extends State<MeteringScreen> {
), ),
MeteringBottomControls( MeteringBottomControls(
onMeasure: () => context.read<MeteringBloc>().add(const MeasureEvent()), onMeasure: () => context.read<MeteringBloc>().add(const MeasureEvent()),
onSettings: () { onSettings: () => Navigator.pushNamed(context, 'settings'),
Navigator.pushNamed(context, 'settings');
},
), ),
], ],
), ),

View file

@ -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<CalibrationDialogEvent, CalibrationDialogState> {
final SettingsInteractor _settingsInteractor;
late double _cameraEvCalibration = _settingsInteractor.cameraEvCalibration;
CalibrationDialogBloc(this._settingsInteractor)
: super(CalibrationDialogState(_settingsInteractor.cameraEvCalibration)) {
on<CameraEvCalibrationChangedEvent>(_onCameraEvCalibrationChanged);
on<CameraEvCalibrationResetEvent>(_onCameraEvCalibrationReset);
on<SaveCalibrationDialogEvent>(_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);
}
}

View file

@ -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();
}

View file

@ -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<SettingsInteractor>()),
child: const CalibrationDialog(),
);
}
}

View file

@ -0,0 +1,5 @@
class CalibrationDialogState {
final double cameraEvCalibration;
const CalibrationDialogState(this.cameraEvCalibration);
}

View file

@ -1,24 +1,22 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:lightmeter/generated/l10n.dart'; import 'package:lightmeter/generated/l10n.dart';
import 'package:lightmeter/res/dimens.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/screens/shared/centered_slider/widget_slider_centered.dart';
import 'package:lightmeter/utils/to_string_signed.dart'; import 'package:lightmeter/utils/to_string_signed.dart';
class CalibrationDialog extends StatefulWidget { import 'bloc_dialog_calibration.dart';
final double cameraEvCalibration; import 'state_dialog_calibration.dart';
const CalibrationDialog({ class CalibrationDialog extends StatefulWidget {
required this.cameraEvCalibration, const CalibrationDialog({super.key});
super.key,
});
@override @override
State<CalibrationDialog> createState() => _CalibrationDialogState(); State<CalibrationDialog> createState() => _CalibrationDialogState();
} }
class _CalibrationDialogState extends State<CalibrationDialog> { class _CalibrationDialogState extends State<CalibrationDialog> {
late double _cameraEvCalibration = widget.cameraEvCalibration;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return AlertDialog( return AlertDialog(
@ -30,21 +28,20 @@ class _CalibrationDialogState extends State<CalibrationDialog> {
), ),
title: Text(S.of(context).calibration), title: Text(S.of(context).calibration),
contentPadding: const EdgeInsets.symmetric(horizontal: Dimens.paddingL), contentPadding: const EdgeInsets.symmetric(horizontal: Dimens.paddingL),
content: Column( content: BlocBuilder<CalibrationDialogBloc, CalibrationDialogState>(
mainAxisSize: MainAxisSize.min, builder: (context, state) => Column(
children: [ mainAxisSize: MainAxisSize.min,
Text(S.of(context).calibrationMessage), children: [
const SizedBox(height: Dimens.grid16), Text(S.of(context).calibrationMessage),
_CalibrationUnit( const SizedBox(height: Dimens.grid16),
title: S.of(context).camera, _CalibrationUnit(
value: _cameraEvCalibration, title: S.of(context).camera,
onChanged: (value) { value: state.cameraEvCalibration,
setState(() { onChanged: (value) => context.read<CalibrationDialogBloc>().add(CameraEvCalibrationChangedEvent(value)),
_cameraEvCalibration = value; onReset: () => context.read<CalibrationDialogBloc>().add(const CameraEvCalibrationResetEvent()),
}); ),
}, ],
), ),
],
), ),
actionsPadding: const EdgeInsets.fromLTRB( actionsPadding: const EdgeInsets.fromLTRB(
Dimens.paddingL, Dimens.paddingL,
@ -58,7 +55,10 @@ class _CalibrationDialogState extends State<CalibrationDialog> {
child: Text(S.of(context).cancel), child: Text(S.of(context).cancel),
), ),
TextButton( TextButton(
onPressed: () => Navigator.of(context).pop(_cameraEvCalibration), onPressed: () {
context.read<CalibrationDialogBloc>().add(const SaveCalibrationDialogEvent());
Navigator.of(context).pop();
},
child: Text(S.of(context).save), child: Text(S.of(context).save),
), ),
], ],
@ -70,11 +70,13 @@ class _CalibrationUnit extends StatelessWidget {
final String title; final String title;
final double value; final double value;
final ValueChanged<double> onChanged; final ValueChanged<double> onChanged;
final VoidCallback onReset;
const _CalibrationUnit({ const _CalibrationUnit({
required this.title, required this.title,
required this.value, required this.value,
required this.onChanged, required this.onChanged,
required this.onReset,
}); });
@override @override
@ -99,9 +101,7 @@ class _CalibrationUnit extends StatelessWidget {
), ),
), ),
IconButton( IconButton(
onPressed: () { onPressed: onReset,
onChanged(0.0);
},
icon: const Icon(Icons.sync), icon: const Icon(Icons.sync),
), ),
], ],

View file

@ -1,9 +0,0 @@
abstract class CalibrationEvent {
const CalibrationEvent();
}
class CameraEvCalibrationChangedEvent extends CalibrationEvent {
final double value;
const CameraEvCalibrationChangedEvent(this.value);
}

View file

@ -1,7 +1,9 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:lightmeter/generated/l10n.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 { class CalibrationListTile extends StatelessWidget {
const CalibrationListTile({super.key}); const CalibrationListTile({super.key});
@ -14,12 +16,11 @@ class CalibrationListTile extends StatelessWidget {
onTap: () { onTap: () {
showDialog<double>( showDialog<double>(
context: context, context: context,
builder: (_) => CalibrationDialog( builder: (_) => Provider.value(
cameraEvCalibration: 0.0, value: context.read<SettingsInteractor>(),
child: const CalibrationDialogProvider(),
), ),
).then((value) { );
if (value != null) {}
});
}, },
); );
} }

View file

@ -1,5 +1,4 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:lightmeter/data/haptics_service.dart'; import 'package:lightmeter/data/haptics_service.dart';
import 'package:lightmeter/data/shared_prefs_service.dart'; import 'package:lightmeter/data/shared_prefs_service.dart';
import 'package:lightmeter/interactors/settings_interactor.dart'; import 'package:lightmeter/interactors/settings_interactor.dart';