ML-58 Metering UX improvements (#63)

* indicate EV value error

* allow nullable ev100 in `CameraContainerBloc`

* log exif keys

* wip

* removed `UserPreferencesService` from `MeteringBloc`

* added error toast

* conflicts

* lints

* allow stop metering if `hasError`

* fixed `AnimatedDialogPicker` inability to close

* Update build.gradle
This commit is contained in:
Vadim 2023-05-16 11:47:53 +02:00 committed by GitHub
parent 5602b1ed80
commit ec9ba1a779
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 203 additions and 150 deletions

2
.vscode/launch.json vendored
View file

@ -8,7 +8,6 @@
"name": "dev (android)", "name": "dev (android)",
"request": "launch", "request": "launch",
"type": "dart", "type": "dart",
//"flutterMode": "profile",
"args": [ "args": [
"--flavor", "--flavor",
"dev", "dev",
@ -21,7 +20,6 @@
"name": "dev (ios)", "name": "dev (ios)",
"request": "launch", "request": "launch",
"type": "dart", "type": "dart",
//"flutterMode": "release",
"args": [ "args": [
"--flavor", "--flavor",
"dev", "dev",

View file

@ -8,7 +8,7 @@ if (localPropertiesFile.exists()) {
def flutterRoot = localProperties.getProperty('flutter.sdk') def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) { if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") throw GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
} }
def flutterVersionCode = localProperties.getProperty('flutter.versionCode') def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
@ -33,6 +33,10 @@ apply plugin: 'com.google.firebase.crashlytics'
apply plugin: 'kotlin-android' apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
gradle.beforeProject({ project->
project.setProperty("target-platform", "android-arm,android-arm64")
})
android { android {
compileSdkVersion 33 compileSdkVersion 33
ndkVersion flutter.ndkVersion ndkVersion flutter.ndkVersion
@ -53,8 +57,7 @@ android {
defaultConfig { defaultConfig {
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 33 targetSdkVersion 33
ndk.abiFilters 'arm64-v8a', 'armeabi-v7a' ndk.abiFilters 'armeabi-v7a', 'arm64-v8a'
targetSdkVersion flutter.targetSdkVersion
/// legacy material-lightmeter ap stopped updating after 60022 /// legacy material-lightmeter ap stopped updating after 60022
/// 7xxxx means that it is a new app /// 7xxxx means that it is a new app
versionCode 70000 + flutterVersionCode.toInteger() versionCode 70000 + flutterVersionCode.toInteger()
@ -92,7 +95,7 @@ android {
signingConfig signingConfigs.release signingConfig signingConfigs.release
minifyEnabled true minifyEnabled true
shrinkResources true shrinkResources true
ndk.abiFilters 'arm64-v8a', 'armeabi-v7a' ndk.abiFilters 'armeabi-v7a', 'arm64-v8a'
} }
} }
} }

View file

@ -28,6 +28,6 @@ subprojects {
project.evaluationDependsOn(':app') project.evaluationDependsOn(':app')
} }
task clean(type: Delete) { tasks.register("clean", Delete) {
delete rootProject.buildDir delete rootProject.buildDir
} }

View file

@ -7,9 +7,11 @@ class HapticsService {
Future<void> responseVibration() async => _tryVibrate(duration: 50, amplitude: 128); Future<void> responseVibration() async => _tryVibrate(duration: 50, amplitude: 128);
Future<void> errorVibration() async => _tryVibrate(duration: 100, amplitude: 128);
Future<void> _tryVibrate({required int duration, required int amplitude}) async { Future<void> _tryVibrate({required int duration, required int amplitude}) async {
if (await _canVibrate()) { if (await _canVibrate()) {
Vibration.vibrate( await Vibration.vibrate(
duration: duration, duration: duration,
amplitude: amplitude, amplitude: amplitude,
); );

View file

@ -4,8 +4,10 @@ import 'package:app_settings/app_settings.dart';
import 'package:lightmeter/data/caffeine_service.dart'; import 'package:lightmeter/data/caffeine_service.dart';
import 'package:lightmeter/data/haptics_service.dart'; import 'package:lightmeter/data/haptics_service.dart';
import 'package:lightmeter/data/light_sensor_service.dart'; import 'package:lightmeter/data/light_sensor_service.dart';
import 'package:lightmeter/data/models/film.dart';
import 'package:lightmeter/data/permissions_service.dart'; import 'package:lightmeter/data/permissions_service.dart';
import 'package:lightmeter/data/shared_prefs_service.dart'; import 'package:lightmeter/data/shared_prefs_service.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
import 'package:permission_handler/permission_handler.dart'; import 'package:permission_handler/permission_handler.dart';
class MeteringInteractor { class MeteringInteractor {
@ -30,16 +32,28 @@ class MeteringInteractor {
double get cameraEvCalibration => _userPreferencesService.cameraEvCalibration; double get cameraEvCalibration => _userPreferencesService.cameraEvCalibration;
double get lightSensorEvCalibration => _userPreferencesService.lightSensorEvCalibration; double get lightSensorEvCalibration => _userPreferencesService.lightSensorEvCalibration;
bool get isHapticsEnabled => _userPreferencesService.haptics; IsoValue get iso => _userPreferencesService.iso;
set iso(IsoValue value) => _userPreferencesService.iso = value;
NdValue get ndFilter => _userPreferencesService.ndFilter;
set ndFilter(NdValue value) => _userPreferencesService.ndFilter = value;
Film get film => _userPreferencesService.film;
set film(Film value) => _userPreferencesService.film = value;
/// Executes vibration if haptics are enabled in settings /// Executes vibration if haptics are enabled in settings
void quickVibration() { Future<void> quickVibration() async {
if (_userPreferencesService.haptics) _hapticsService.quickVibration(); if (_userPreferencesService.haptics) await _hapticsService.quickVibration();
} }
/// Executes vibration if haptics are enabled in settings /// Executes vibration if haptics are enabled in settings
void responseVibration() { Future<void> responseVibration() async {
if (_userPreferencesService.haptics) _hapticsService.responseVibration(); if (_userPreferencesService.haptics) await _hapticsService.responseVibration();
}
/// Executes vibration if haptics are enabled in settings
Future<void> errorVibration() async {
if (_userPreferencesService.haptics) await _hapticsService.errorVibration();
} }
Future<bool> checkCameraPermission() async { Future<bool> checkCameraPermission() async {

View file

@ -4,7 +4,6 @@ import 'dart:math';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:lightmeter/data/models/exposure_pair.dart'; import 'package:lightmeter/data/models/exposure_pair.dart';
import 'package:lightmeter/data/models/film.dart'; import 'package:lightmeter/data/models/film.dart';
import 'package:lightmeter/data/shared_prefs_service.dart';
import 'package:lightmeter/interactors/metering_interactor.dart'; import 'package:lightmeter/interactors/metering_interactor.dart';
import 'package:lightmeter/screens/metering/communication/bloc_communication_metering.dart'; import 'package:lightmeter/screens/metering/communication/bloc_communication_metering.dart';
import 'package:lightmeter/screens/metering/communication/event_communication_metering.dart' import 'package:lightmeter/screens/metering/communication/event_communication_metering.dart'
@ -17,7 +16,6 @@ import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
class MeteringBloc extends Bloc<MeteringEvent, MeteringState> { class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
final MeteringCommunicationBloc _communicationBloc; final MeteringCommunicationBloc _communicationBloc;
final UserPreferencesService _userPreferencesService;
final MeteringInteractor _meteringInteractor; final MeteringInteractor _meteringInteractor;
late final StreamSubscription<communication_states.ScreenState> _communicationSubscription; late final StreamSubscription<communication_states.ScreenState> _communicationSubscription;
@ -29,25 +27,25 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
EquipmentProfileData _equipmentProfileData; EquipmentProfileData _equipmentProfileData;
StopType stopType; StopType stopType;
late IsoValue _iso = _userPreferencesService.iso; late IsoValue _iso = _meteringInteractor.iso;
late NdValue _nd = _userPreferencesService.ndFilter; late NdValue _nd = _meteringInteractor.ndFilter;
late Film _film = _userPreferencesService.film; late Film _film = _meteringInteractor.film;
double _ev100 = 0.0; double? _ev100 = 0.0;
bool _isMeteringInProgress = false; bool _isMeteringInProgress = false;
MeteringBloc( MeteringBloc(
this._communicationBloc, this._communicationBloc,
this._userPreferencesService,
this._meteringInteractor, this._meteringInteractor,
this._equipmentProfileData, this._equipmentProfileData,
this.stopType, this.stopType,
) : super( ) : super(
MeteringEndedState( MeteringDataState(
ev: 0.0, ev: 0.0,
film: _userPreferencesService.film, film: _meteringInteractor.film,
iso: _userPreferencesService.iso, iso: _meteringInteractor.iso,
nd: _userPreferencesService.ndFilter, nd: _meteringInteractor.ndFilter,
exposurePairs: const [], exposurePairs: const [],
continuousMetering: false,
), ),
) { ) {
_communicationSubscription = _communicationBloc.stream _communicationSubscription = _communicationBloc.stream
@ -62,6 +60,7 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
on<NdChangedEvent>(_onNdChanged); on<NdChangedEvent>(_onNdChanged);
on<MeasureEvent>(_onMeasure); on<MeasureEvent>(_onMeasure);
on<MeasuredEvent>(_onMeasured); on<MeasuredEvent>(_onMeasured);
on<MeasureErrorEvent>(_onMeasureError);
} }
@override @override
@ -73,13 +72,13 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
void _onCommunicationState(communication_states.ScreenState communicationState) { void _onCommunicationState(communication_states.ScreenState communicationState) {
if (communicationState is communication_states.MeasuredState) { if (communicationState is communication_states.MeasuredState) {
_isMeteringInProgress = communicationState is communication_states.MeteringInProgressState; _isMeteringInProgress = communicationState is communication_states.MeteringInProgressState;
add(MeasuredEvent(communicationState.ev100)); _handleEv100(communicationState.ev100);
} }
} }
void _onStopTypeChanged(StopTypeChangedEvent event, Emitter emit) { void _onStopTypeChanged(StopTypeChangedEvent event, Emitter emit) {
stopType = event.stopType; stopType = event.stopType;
_emitMeasuredState(emit); _updateMeasurements();
} }
void _onEquipmentProfileChanged(EquipmentProfileChangedEvent event, Emitter emit) { void _onEquipmentProfileChanged(EquipmentProfileChangedEvent event, Emitter emit) {
@ -88,17 +87,17 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
/// Update selected ISO value, if selected equipment profile /// Update selected ISO value, if selected equipment profile
/// doesn't contain currently selected value /// doesn't contain currently selected value
if (!event.equipmentProfileData.isoValues.any((v) => _iso.value == v.value)) { if (!event.equipmentProfileData.isoValues.any((v) => _iso.value == v.value)) {
_userPreferencesService.iso = event.equipmentProfileData.isoValues.first; _meteringInteractor.iso = event.equipmentProfileData.isoValues.first;
_iso = event.equipmentProfileData.isoValues.first; _iso = event.equipmentProfileData.isoValues.first;
} }
/// The same for ND filter /// The same for ND filter
if (!event.equipmentProfileData.ndValues.any((v) => _nd.value == v.value)) { if (!event.equipmentProfileData.ndValues.any((v) => _nd.value == v.value)) {
_userPreferencesService.ndFilter = event.equipmentProfileData.ndValues.first; _meteringInteractor.ndFilter = event.equipmentProfileData.ndValues.first;
_nd = event.equipmentProfileData.ndValues.first; _nd = event.equipmentProfileData.ndValues.first;
} }
_emitMeasuredState(emit); _updateMeasurements();
} }
void _onFilmChanged(FilmChangedEvent event, Emitter emit) { void _onFilmChanged(FilmChangedEvent event, Emitter emit) {
@ -110,55 +109,75 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
add(IsoChangedEvent(newIso)); add(IsoChangedEvent(newIso));
} }
_film = event.data; _film = event.data;
_userPreferencesService.film = event.data; _meteringInteractor.film = event.data;
_emitMeasuredState(emit); _updateMeasurements();
} }
void _onIsoChanged(IsoChangedEvent event, Emitter emit) { void _onIsoChanged(IsoChangedEvent event, Emitter emit) {
if (event.isoValue.value != _film.iso) { if (event.isoValue.value != _film.iso) {
_film = Film.values.first; _film = Film.values.first;
} }
_userPreferencesService.iso = event.isoValue; _meteringInteractor.iso = event.isoValue;
_iso = event.isoValue; _iso = event.isoValue;
_emitMeasuredState(emit); _updateMeasurements();
} }
void _onNdChanged(NdChangedEvent event, Emitter emit) { void _onNdChanged(NdChangedEvent event, Emitter emit) {
_userPreferencesService.ndFilter = event.ndValue; _meteringInteractor.ndFilter = event.ndValue;
_nd = event.ndValue; _nd = event.ndValue;
_emitMeasuredState(emit); _updateMeasurements();
} }
void _onMeasure(_, Emitter emit) { void _onMeasure(MeasureEvent _, Emitter emit) {
_meteringInteractor.quickVibration(); _meteringInteractor.quickVibration();
_communicationBloc.add(const communication_events.MeasureEvent()); _communicationBloc.add(const communication_events.MeasureEvent());
_isMeteringInProgress = true; _isMeteringInProgress = true;
emit(const LoadingState()); emit(
LoadingState(
film: _film,
iso: _iso,
nd: _nd,
),
);
}
void _updateMeasurements() => _handleEv100(_ev100);
void _handleEv100(double? ev100) {
if (ev100 == null || ev100.isNaN || ev100.isInfinite) {
add(const MeasureErrorEvent());
} else {
add(MeasuredEvent(ev100));
}
} }
void _onMeasured(MeasuredEvent event, Emitter emit) { void _onMeasured(MeasuredEvent event, Emitter emit) {
_meteringInteractor.responseVibration(); _meteringInteractor.responseVibration();
_ev100 = event.ev100; _ev100 = event.ev100;
_emitMeasuredState(emit); final ev = event.ev100 + log2(_iso.value / 100) - _nd.stopReduction;
emit(
MeteringDataState(
ev: ev,
film: _film,
iso: _iso,
nd: _nd,
exposurePairs: _buildExposureValues(ev),
continuousMetering: _isMeteringInProgress,
),
);
} }
void _emitMeasuredState(Emitter emit) { void _onMeasureError(MeasureErrorEvent _, Emitter emit) {
final ev = _ev100 + log2(_iso.value / 100) - _nd.stopReduction; _meteringInteractor.errorVibration();
_ev100 = null;
emit( emit(
_isMeteringInProgress MeteringDataState(
? MeteringInProgressState( ev: null,
ev: ev,
film: _film, film: _film,
iso: _iso, iso: _iso,
nd: _nd, nd: _nd,
exposurePairs: _buildExposureValues(ev), exposurePairs: const [],
) continuousMetering: _isMeteringInProgress,
: MeteringEndedState(
ev: ev,
film: _film,
iso: _iso,
nd: _nd,
exposurePairs: _buildExposureValues(ev),
), ),
); );
} }

View file

@ -15,7 +15,7 @@ class MeasureEvent extends ScreenEvent {
} }
abstract class MeasuredEvent extends SourceEvent { abstract class MeasuredEvent extends SourceEvent {
final double ev100; final double? ev100;
const MeasuredEvent(this.ev100); const MeasuredEvent(this.ev100);
} }

View file

@ -19,7 +19,7 @@ class MeasureState extends SourceState {
} }
abstract class MeasuredState extends ScreenState { abstract class MeasuredState extends ScreenState {
final double ev100; final double? ev100;
const MeasuredState(this.ev100); const MeasuredState(this.ev100);
} }

View file

@ -6,11 +6,13 @@ import 'package:lightmeter/screens/shared/filled_circle/widget_circle_filled.dar
class MeteringMeasureButton extends StatefulWidget { class MeteringMeasureButton extends StatefulWidget {
final double? ev; final double? ev;
final bool isMetering; final bool isMetering;
final bool hasError;
final VoidCallback onTap; final VoidCallback onTap;
const MeteringMeasureButton({ const MeteringMeasureButton({
required this.ev, required this.ev,
required this.isMetering, required this.isMetering,
required this.hasError,
required this.onTap, required this.onTap,
super.key, super.key,
}); });
@ -33,7 +35,7 @@ class _MeteringMeasureButtonState extends State<MeteringMeasureButton> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return IgnorePointer( return IgnorePointer(
ignoring: widget.isMetering && widget.ev == null, ignoring: widget.isMetering && widget.ev == null && !widget.hasError,
child: GestureDetector( child: GestureDetector(
onTap: widget.onTap, onTap: widget.onTap,
onTapDown: (_) { onTapDown: (_) {
@ -63,7 +65,13 @@ class _MeteringMeasureButtonState extends State<MeteringMeasureButton> {
color: Theme.of(context).colorScheme.onSurface, color: Theme.of(context).colorScheme.onSurface,
size: Dimens.grid72 - Dimens.grid8, size: Dimens.grid72 - Dimens.grid8,
child: Center( child: Center(
child: widget.ev != null ? _EvValueText(ev: widget.ev!) : null, child: widget.hasError
? Icon(
Icons.error_outline,
color: Theme.of(context).colorScheme.surface,
size: Dimens.grid24,
)
: (widget.ev != null ? _EvValueText(ev: widget.ev!) : null),
), ),
), ),
), ),
@ -91,13 +99,6 @@ class _EvValueText extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (ev.isNaN || ev.isInfinite) {
return Icon(
Icons.error,
color: Theme.of(context).colorScheme.surface,
);
}
final theme = Theme.of(context); final theme = Theme.of(context);
return Text( return Text(
'${ev.toStringAsFixed(1)}\n${S.of(context).ev}', '${ev.toStringAsFixed(1)}\n${S.of(context).ev}',

View file

@ -6,6 +6,7 @@ import 'package:lightmeter/screens/metering/components/bottom_controls/widget_bo
class MeteringBottomControlsProvider extends StatelessWidget { class MeteringBottomControlsProvider extends StatelessWidget {
final double? ev; final double? ev;
final bool isMetering; final bool isMetering;
final bool hasError;
final VoidCallback? onSwitchEvSourceType; final VoidCallback? onSwitchEvSourceType;
final VoidCallback onMeasure; final VoidCallback onMeasure;
final VoidCallback onSettings; final VoidCallback onSettings;
@ -13,6 +14,7 @@ class MeteringBottomControlsProvider extends StatelessWidget {
const MeteringBottomControlsProvider({ const MeteringBottomControlsProvider({
required this.ev, required this.ev,
required this.isMetering, required this.isMetering,
required this.hasError,
required this.onSwitchEvSourceType, required this.onSwitchEvSourceType,
required this.onMeasure, required this.onMeasure,
required this.onSettings, required this.onSettings,
@ -36,6 +38,7 @@ class MeteringBottomControlsProvider extends StatelessWidget {
child: MeteringBottomControls( child: MeteringBottomControls(
ev: ev, ev: ev,
isMetering: isMetering, isMetering: isMetering,
hasError: hasError,
onSwitchEvSourceType: onSwitchEvSourceType, onSwitchEvSourceType: onSwitchEvSourceType,
onMeasure: onMeasure, onMeasure: onMeasure,
onSettings: onSettings, onSettings: onSettings,

View file

@ -7,6 +7,7 @@ import 'package:provider/provider.dart';
class MeteringBottomControls extends StatelessWidget { class MeteringBottomControls extends StatelessWidget {
final double? ev; final double? ev;
final bool isMetering; final bool isMetering;
final bool hasError;
final VoidCallback? onSwitchEvSourceType; final VoidCallback? onSwitchEvSourceType;
final VoidCallback onMeasure; final VoidCallback onMeasure;
final VoidCallback onSettings; final VoidCallback onSettings;
@ -14,6 +15,7 @@ class MeteringBottomControls extends StatelessWidget {
const MeteringBottomControls({ const MeteringBottomControls({
required this.ev, required this.ev,
required this.isMetering, required this.isMetering,
required this.hasError,
required this.onSwitchEvSourceType, required this.onSwitchEvSourceType,
required this.onMeasure, required this.onMeasure,
required this.onSettings, required this.onSettings,
@ -54,6 +56,7 @@ class MeteringBottomControls extends StatelessWidget {
MeteringMeasureButton( MeteringMeasureButton(
ev: ev, ev: ev,
isMetering: isMetering, isMetering: isMetering,
hasError: hasError,
onTap: onMeasure, onTap: onMeasure,
), ),
Expanded( Expanded(

View file

@ -1,6 +1,7 @@
import 'dart:async'; import 'dart:async';
import 'dart:developer';
import 'dart:io'; import 'dart:io';
import 'dart:math'; import 'dart:math' as math;
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:camera/camera.dart'; import 'package:camera/camera.dart';
@ -34,7 +35,7 @@ class CameraContainerBloc extends EvSourceBlocBase<CameraContainerEvent, CameraC
double _exposureStep = 0.0; double _exposureStep = 0.0;
double _currentExposureOffset = 0.0; double _currentExposureOffset = 0.0;
double _ev100 = 0.0; double? _ev100 = 0.0;
CameraContainerBloc( CameraContainerBloc(
this._meteringInteractor, this._meteringInteractor,
@ -67,14 +68,19 @@ class CameraContainerBloc extends EvSourceBlocBase<CameraContainerEvent, CameraC
@override @override
void onCommunicationState(communication_states.SourceState communicationState) { void onCommunicationState(communication_states.SourceState communicationState) {
if (communicationState is communication_states.MeasureState) { if (communicationState is communication_states.MeasureState) {
if (_canTakePhoto) {
_takePhoto().then((ev100Raw) { _takePhoto().then((ev100Raw) {
if (ev100Raw != null) { if (ev100Raw != null) {
_ev100 = ev100Raw + _meteringInteractor.cameraEvCalibration; _ev100 = ev100Raw + _meteringInteractor.cameraEvCalibration;
communicationBloc.add(communication_event.MeteringEndedEvent(_ev100)); communicationBloc.add(communication_event.MeteringEndedEvent(_ev100));
} else {
_ev100 = null;
communicationBloc.add(const communication_event.MeteringEndedEvent(null));
} }
}); });
} }
} }
}
Future<void> _onRequestPermission(_, Emitter emit) async { Future<void> _onRequestPermission(_, Emitter emit) async {
final hasPermission = await _meteringInteractor.requestPermission(); final hasPermission = await _meteringInteractor.requestPermission();
@ -118,7 +124,7 @@ class CameraContainerBloc extends EvSourceBlocBase<CameraContainerEvent, CameraC
_zoomRange = await Future.wait<double>([ _zoomRange = await Future.wait<double>([
_cameraController!.getMinZoomLevel(), _cameraController!.getMinZoomLevel(),
_cameraController!.getMaxZoomLevel(), _cameraController!.getMaxZoomLevel(),
]).then((levels) => RangeValues(levels[0], min(_maxZoom, levels[1]))); ]).then((levels) => RangeValues(levels[0], math.min(_maxZoom, levels[1])));
_currentZoom = _zoomRange!.start; _currentZoom = _zoomRange!.start;
_exposureOffsetRange = await Future.wait<double>([ _exposureOffsetRange = await Future.wait<double>([
@ -126,8 +132,8 @@ class CameraContainerBloc extends EvSourceBlocBase<CameraContainerEvent, CameraC
_cameraController!.getMaxExposureOffset(), _cameraController!.getMaxExposureOffset(),
]).then( ]).then(
(levels) => RangeValues( (levels) => RangeValues(
max(_exposureMaxRange.start, levels[0]), math.max(_exposureMaxRange.start, levels[0]),
min(_exposureMaxRange.end, levels[1]), math.min(_exposureMaxRange.end, levels[1]),
), ),
); );
await _cameraController!.getExposureOffsetStepSize().then((value) { await _cameraController!.getExposureOffsetStepSize().then((value) {
@ -172,28 +178,31 @@ class CameraContainerBloc extends EvSourceBlocBase<CameraContainerEvent, CameraC
); );
} }
Future<double?> _takePhoto() async { bool get _canTakePhoto => !(_cameraController == null ||
if (_cameraController == null ||
!_cameraController!.value.isInitialized || !_cameraController!.value.isInitialized ||
_cameraController!.value.isTakingPicture) { _cameraController!.value.isTakingPicture);
return null;
}
Future<double?> _takePhoto() async {
try { try {
final file = await _cameraController!.takePicture(); final file = await _cameraController!.takePicture();
final Uint8List bytes = await file.readAsBytes(); final Uint8List bytes = await file.readAsBytes();
Directory(file.path).deleteSync(recursive: true); Directory(file.path).deleteSync(recursive: true);
final tags = await readExifFromBytes(bytes); final tags = await readExifFromBytes(bytes);
final iso = double.parse("${tags["EXIF ISOSpeedRatings"]}"); final iso = double.tryParse("${tags["EXIF ISOSpeedRatings"]}");
final apertureValueRatio = (tags["EXIF FNumber"]!.values as IfdRatios).ratios.first; final apertureValueRatio = (tags["EXIF FNumber"]?.values as IfdRatios?)?.ratios.first;
final speedValueRatio = (tags["EXIF ExposureTime"]?.values as IfdRatios?)?.ratios.first;
if (iso == null || apertureValueRatio == null || speedValueRatio == null) {
log('Error parsing EXIF: ${tags.keys}');
return null;
}
final aperture = apertureValueRatio.numerator / apertureValueRatio.denominator; final aperture = apertureValueRatio.numerator / apertureValueRatio.denominator;
final speedValueRatio = (tags["EXIF ExposureTime"]!.values as IfdRatios).ratios.first;
final speed = speedValueRatio.numerator / speedValueRatio.denominator; final speed = speedValueRatio.numerator / speedValueRatio.denominator;
return log2(pow(aperture, 2)) - log2(speed) - log2(iso / 100); return log2(math.pow(aperture, 2)) - log2(speed) - log2(iso / 100);
} on CameraException catch (e) { } on CameraException catch (e) {
debugPrint('Error: ${e.code}\nError Message: ${e.description}'); log('Error: ${e.code}\nError Message: ${e.description}');
return null; return null;
} }
} }

View file

@ -3,8 +3,9 @@ import 'package:flutter/material.dart';
import 'package:lightmeter/screens/metering/components/shared/readings_container/components/animated_dialog_picker/components/animated_dialog/widget_dialog_animated.dart'; import 'package:lightmeter/screens/metering/components/shared/readings_container/components/animated_dialog_picker/components/animated_dialog/widget_dialog_animated.dart';
import 'package:lightmeter/screens/metering/components/shared/readings_container/components/animated_dialog_picker/components/dialog_picker/widget_picker_dialog.dart'; import 'package:lightmeter/screens/metering/components/shared/readings_container/components/animated_dialog_picker/components/dialog_picker/widget_picker_dialog.dart';
class AnimatedDialogPicker<T> extends StatelessWidget { // Has to be stateful, so that [GlobalKey] is not recreated.
final _key = GlobalKey<AnimatedDialogState>(); // Otherwise use will no be able to close the dialog after EV value has changed.
class AnimatedDialogPicker<T> extends StatefulWidget {
final IconData icon; final IconData icon;
final String title; final String title;
final String? subtitle; final String? subtitle;
@ -15,7 +16,7 @@ class AnimatedDialogPicker<T> extends StatelessWidget {
final ValueChanged<T> onChanged; final ValueChanged<T> onChanged;
final Widget closedChild; final Widget closedChild;
AnimatedDialogPicker({ const AnimatedDialogPicker({
required this.icon, required this.icon,
required this.title, required this.title,
this.subtitle, this.subtitle,
@ -28,24 +29,31 @@ class AnimatedDialogPicker<T> extends StatelessWidget {
super.key, super.key,
}); });
@override
State<AnimatedDialogPicker<T>> createState() => _AnimatedDialogPickerState<T>();
}
class _AnimatedDialogPickerState<T> extends State<AnimatedDialogPicker<T>> {
final _key = GlobalKey<AnimatedDialogState>();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return AnimatedDialog( return AnimatedDialog(
key: _key, key: _key,
closedChild: closedChild, closedChild: widget.closedChild,
openedChild: DialogPicker<T>( openedChild: DialogPicker<T>(
icon: icon, icon: widget.icon,
title: title, title: widget.title,
subtitle: subtitle, subtitle: widget.subtitle,
initialValue: selectedValue, initialValue: widget.selectedValue,
values: values, values: widget.values,
itemTitleBuilder: itemTitleBuilder, itemTitleBuilder: widget.itemTitleBuilder,
itemTrailingBuilder: itemTrailingBuilder, itemTrailingBuilder: widget.itemTrailingBuilder,
onCancel: () { onCancel: () {
_key.currentState?.close(); _key.currentState?.close();
}, },
onSelect: (value) { onSelect: (value) {
_key.currentState?.close().then((_) => onChanged(value)); _key.currentState?.close().then((_) => widget.onChanged(value));
}, },
), ),
); );

View file

@ -11,7 +11,6 @@ import 'package:lightmeter/screens/metering/components/shared/readings_container
import 'package:lightmeter/screens/metering/components/shared/readings_container/components/reading_value_container/widget_container_reading_value.dart'; import 'package:lightmeter/screens/metering/components/shared/readings_container/components/reading_value_container/widget_container_reading_value.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
/// Contains a column of fastest & slowest exposure pairs + a row of ISO and ND pickers
class ReadingsContainer extends StatelessWidget { class ReadingsContainer extends StatelessWidget {
final ExposurePair? fastest; final ExposurePair? fastest;
final ExposurePair? slowest; final ExposurePair? slowest;

View file

@ -44,3 +44,7 @@ class MeasuredEvent extends MeteringEvent {
const MeasuredEvent(this.ev100); const MeasuredEvent(this.ev100);
} }
class MeasureErrorEvent extends MeteringEvent {
const MeasureErrorEvent();
}

View file

@ -37,7 +37,6 @@ class _MeteringFlowState extends State<MeteringFlow> {
BlocProvider( BlocProvider(
create: (context) => MeteringBloc( create: (context) => MeteringBloc(
context.read<MeteringCommunicationBloc>(), context.read<MeteringCommunicationBloc>(),
context.read<UserPreferencesService>(),
context.read<MeteringInteractor>(), context.read<MeteringInteractor>(),
EquipmentProfile.of(context, listen: false), EquipmentProfile.of(context, listen: false),
context.read<StopType>(), context.read<StopType>(),

View file

@ -44,26 +44,25 @@ class _MeteringScreenState extends State<MeteringScreen> {
children: [ children: [
Expanded( Expanded(
child: BlocBuilder<MeteringBloc, MeteringState>( child: BlocBuilder<MeteringBloc, MeteringState>(
buildWhen: (_, current) => current is MeteringDataState, builder: (_, state) => _MeteringContainerBuidler(
builder: (_, state) => state is MeteringDataState fastest: state is MeteringDataState ? state.fastest : null,
? _MeteringContainerBuidler( slowest: state is MeteringDataState ? state.slowest : null,
fastest: state.fastest, exposurePairs: state is MeteringDataState ? state.exposurePairs : [],
slowest: state.slowest,
film: state.film, film: state.film,
iso: state.iso, iso: state.iso,
nd: state.nd, nd: state.nd,
onFilmChanged: (value) => _bloc.add(FilmChangedEvent(value)), onFilmChanged: (value) => _bloc.add(FilmChangedEvent(value)),
onIsoChanged: (value) => _bloc.add(IsoChangedEvent(value)), onIsoChanged: (value) => _bloc.add(IsoChangedEvent(value)),
onNdChanged: (value) => _bloc.add(NdChangedEvent(value)), onNdChanged: (value) => _bloc.add(NdChangedEvent(value)),
exposurePairs: state.exposurePairs, ),
)
: const SizedBox.shrink(),
), ),
), ),
BlocBuilder<MeteringBloc, MeteringState>( BlocBuilder<MeteringBloc, MeteringState>(
builder: (context, state) => MeteringBottomControlsProvider( builder: (context, state) => MeteringBottomControlsProvider(
ev: state is MeteringDataState ? state.ev : null, ev: state is MeteringDataState ? state.ev : null,
isMetering: state is LoadingState || state is MeteringInProgressState, isMetering:
state is LoadingState || state is MeteringDataState && state.continuousMetering,
hasError: state is MeteringDataState && state.hasError,
onSwitchEvSourceType: context.read<Environment>().hasLightSensor onSwitchEvSourceType: context.read<Environment>().hasLightSensor
? EvSourceTypeProvider.of(context).toggleType ? EvSourceTypeProvider.of(context).toggleType
: null, : null,

View file

@ -5,48 +5,40 @@ import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
@immutable @immutable
abstract class MeteringState { abstract class MeteringState {
const MeteringState();
}
class LoadingState extends MeteringState {
const LoadingState();
}
abstract class MeteringDataState extends MeteringState {
final double ev;
final Film film; final Film film;
final IsoValue iso; final IsoValue iso;
final NdValue nd; final NdValue nd;
final List<ExposurePair> exposurePairs;
const MeteringDataState({ const MeteringState({
required this.ev,
required this.film, required this.film,
required this.iso, required this.iso,
required this.nd, required this.nd,
});
}
class LoadingState extends MeteringState {
const LoadingState({
required super.film,
required super.iso,
required super.nd,
});
}
class MeteringDataState extends MeteringState {
final double? ev;
final List<ExposurePair> exposurePairs;
final bool continuousMetering;
const MeteringDataState({
required this.ev,
required super.film,
required super.iso,
required super.nd,
required this.exposurePairs, required this.exposurePairs,
required this.continuousMetering,
}); });
ExposurePair? get fastest => exposurePairs.isEmpty ? null : exposurePairs.first; ExposurePair? get fastest => exposurePairs.isEmpty ? null : exposurePairs.first;
ExposurePair? get slowest => exposurePairs.isEmpty ? null : exposurePairs.last; ExposurePair? get slowest => exposurePairs.isEmpty ? null : exposurePairs.last;
} bool get hasError => ev == null;
class MeteringInProgressState extends MeteringDataState {
const MeteringInProgressState({
required super.ev,
required super.film,
required super.iso,
required super.nd,
required super.exposurePairs,
});
}
class MeteringEndedState extends MeteringDataState {
const MeteringEndedState({
required super.ev,
required super.film,
required super.iso,
required super.nd,
required super.exposurePairs,
});
} }

View file

@ -27,7 +27,7 @@ dependencies:
url: "https://github.com/vodemn/m3_lightmeter_resources" url: "https://github.com/vodemn/m3_lightmeter_resources"
ref: main ref: main
material_color_utilities: 0.2.0 material_color_utilities: 0.2.0
package_info_plus: 3.0.2 package_info_plus: 4.0.0
permission_handler: 10.2.0 permission_handler: 10.2.0
provider: 6.0.4 provider: 6.0.4
shared_preferences: 2.0.15 shared_preferences: 2.0.15