mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-24 00:10:47 +00:00
implemented CalibrationDialog
This commit is contained in:
parent
ab5b747831
commit
dda0a38a0f
12 changed files with 118 additions and 48 deletions
|
@ -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,
|
||||||
|
|
|
@ -17,3 +17,7 @@ class ExposureOffsetChangedEvent extends CameraEvent {
|
||||||
|
|
||||||
const ExposureOffsetChangedEvent(this.value);
|
const ExposureOffsetChangedEvent(this.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ExposureOffsetResetEvent extends CameraEvent {
|
||||||
|
const ExposureOffsetResetEvent();
|
||||||
|
}
|
||||||
|
|
|
@ -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');
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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();
|
||||||
|
}
|
|
@ -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(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
class CalibrationDialogState {
|
||||||
|
final double cameraEvCalibration;
|
||||||
|
|
||||||
|
const CalibrationDialogState(this.cameraEvCalibration);
|
||||||
|
}
|
|
@ -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,22 +28,21 @@ 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>(
|
||||||
|
builder: (context, state) => Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
Text(S.of(context).calibrationMessage),
|
Text(S.of(context).calibrationMessage),
|
||||||
const SizedBox(height: Dimens.grid16),
|
const SizedBox(height: Dimens.grid16),
|
||||||
_CalibrationUnit(
|
_CalibrationUnit(
|
||||||
title: S.of(context).camera,
|
title: S.of(context).camera,
|
||||||
value: _cameraEvCalibration,
|
value: state.cameraEvCalibration,
|
||||||
onChanged: (value) {
|
onChanged: (value) => context.read<CalibrationDialogBloc>().add(CameraEvCalibrationChangedEvent(value)),
|
||||||
setState(() {
|
onReset: () => context.read<CalibrationDialogBloc>().add(const CameraEvCalibrationResetEvent()),
|
||||||
_cameraEvCalibration = value;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
),
|
||||||
actionsPadding: const EdgeInsets.fromLTRB(
|
actionsPadding: const EdgeInsets.fromLTRB(
|
||||||
Dimens.paddingL,
|
Dimens.paddingL,
|
||||||
Dimens.paddingM,
|
Dimens.paddingM,
|
||||||
|
@ -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),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
abstract class CalibrationEvent {
|
|
||||||
const CalibrationEvent();
|
|
||||||
}
|
|
||||||
|
|
||||||
class CameraEvCalibrationChangedEvent extends CalibrationEvent {
|
|
||||||
final double value;
|
|
||||||
|
|
||||||
const CameraEvCalibrationChangedEvent(this.value);
|
|
||||||
}
|
|
|
@ -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) {}
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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';
|
||||||
|
|
Loading…
Reference in a new issue