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

View file

@ -17,3 +17,7 @@ class ExposureOffsetChangedEvent extends CameraEvent {
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: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<MeteringScreen> {
),
MeteringBottomControls(
onMeasure: () => context.read<MeteringBloc>().add(const MeasureEvent()),
onSettings: () {
Navigator.pushNamed(context, 'settings');
},
onSettings: () => 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_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<CalibrationDialog> createState() => _CalibrationDialogState();
}
class _CalibrationDialogState extends State<CalibrationDialog> {
late double _cameraEvCalibration = widget.cameraEvCalibration;
@override
Widget build(BuildContext context) {
return AlertDialog(
@ -30,21 +28,20 @@ class _CalibrationDialogState extends State<CalibrationDialog> {
),
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<CalibrationDialogBloc, CalibrationDialogState>(
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<CalibrationDialogBloc>().add(CameraEvCalibrationChangedEvent(value)),
onReset: () => context.read<CalibrationDialogBloc>().add(const CameraEvCalibrationResetEvent()),
),
],
),
),
actionsPadding: const EdgeInsets.fromLTRB(
Dimens.paddingL,
@ -58,7 +55,10 @@ class _CalibrationDialogState extends State<CalibrationDialog> {
child: Text(S.of(context).cancel),
),
TextButton(
onPressed: () => Navigator.of(context).pop(_cameraEvCalibration),
onPressed: () {
context.read<CalibrationDialogBloc>().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<double> 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),
),
],

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: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<double>(
context: context,
builder: (_) => CalibrationDialog(
cameraEvCalibration: 0.0,
builder: (_) => Provider.value(
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_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';