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)",
"request": "launch",
"type": "dart",
//"flutterMode": "profile",
"args": [
"--flavor",
"dev",
@ -21,7 +20,6 @@
"name": "dev (ios)",
"request": "launch",
"type": "dart",
//"flutterMode": "release",
"args": [
"--flavor",
"dev",

View file

@ -8,7 +8,7 @@ if (localPropertiesFile.exists()) {
def flutterRoot = localProperties.getProperty('flutter.sdk')
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')
@ -33,6 +33,10 @@ apply plugin: 'com.google.firebase.crashlytics'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
gradle.beforeProject({ project->
project.setProperty("target-platform", "android-arm,android-arm64")
})
android {
compileSdkVersion 33
ndkVersion flutter.ndkVersion
@ -53,8 +57,7 @@ android {
defaultConfig {
minSdkVersion 21
targetSdkVersion 33
ndk.abiFilters 'arm64-v8a', 'armeabi-v7a'
targetSdkVersion flutter.targetSdkVersion
ndk.abiFilters 'armeabi-v7a', 'arm64-v8a'
/// legacy material-lightmeter ap stopped updating after 60022
/// 7xxxx means that it is a new app
versionCode 70000 + flutterVersionCode.toInteger()
@ -92,7 +95,7 @@ android {
signingConfig signingConfigs.release
minifyEnabled 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')
}
task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}

View file

@ -7,9 +7,11 @@ class HapticsService {
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 {
if (await _canVibrate()) {
Vibration.vibrate(
await Vibration.vibrate(
duration: duration,
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/haptics_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/shared_prefs_service.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
import 'package:permission_handler/permission_handler.dart';
class MeteringInteractor {
@ -30,16 +32,28 @@ class MeteringInteractor {
double get cameraEvCalibration => _userPreferencesService.cameraEvCalibration;
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
void quickVibration() {
if (_userPreferencesService.haptics) _hapticsService.quickVibration();
Future<void> quickVibration() async {
if (_userPreferencesService.haptics) await _hapticsService.quickVibration();
}
/// Executes vibration if haptics are enabled in settings
void responseVibration() {
if (_userPreferencesService.haptics) _hapticsService.responseVibration();
Future<void> responseVibration() async {
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 {

View file

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

View file

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

View file

@ -19,7 +19,7 @@ class MeasureState extends SourceState {
}
abstract class MeasuredState extends ScreenState {
final double ev100;
final double? 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 {
final double? ev;
final bool isMetering;
final bool hasError;
final VoidCallback onTap;
const MeteringMeasureButton({
required this.ev,
required this.isMetering,
required this.hasError,
required this.onTap,
super.key,
});
@ -33,7 +35,7 @@ class _MeteringMeasureButtonState extends State<MeteringMeasureButton> {
@override
Widget build(BuildContext context) {
return IgnorePointer(
ignoring: widget.isMetering && widget.ev == null,
ignoring: widget.isMetering && widget.ev == null && !widget.hasError,
child: GestureDetector(
onTap: widget.onTap,
onTapDown: (_) {
@ -63,7 +65,13 @@ class _MeteringMeasureButtonState extends State<MeteringMeasureButton> {
color: Theme.of(context).colorScheme.onSurface,
size: Dimens.grid72 - Dimens.grid8,
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
Widget build(BuildContext context) {
if (ev.isNaN || ev.isInfinite) {
return Icon(
Icons.error,
color: Theme.of(context).colorScheme.surface,
);
}
final theme = Theme.of(context);
return Text(
'${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 {
final double? ev;
final bool isMetering;
final bool hasError;
final VoidCallback? onSwitchEvSourceType;
final VoidCallback onMeasure;
final VoidCallback onSettings;
@ -13,6 +14,7 @@ class MeteringBottomControlsProvider extends StatelessWidget {
const MeteringBottomControlsProvider({
required this.ev,
required this.isMetering,
required this.hasError,
required this.onSwitchEvSourceType,
required this.onMeasure,
required this.onSettings,
@ -36,6 +38,7 @@ class MeteringBottomControlsProvider extends StatelessWidget {
child: MeteringBottomControls(
ev: ev,
isMetering: isMetering,
hasError: hasError,
onSwitchEvSourceType: onSwitchEvSourceType,
onMeasure: onMeasure,
onSettings: onSettings,

View file

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

View file

@ -1,6 +1,7 @@
import 'dart:async';
import 'dart:developer';
import 'dart:io';
import 'dart:math';
import 'dart:math' as math;
import 'dart:typed_data';
import 'package:camera/camera.dart';
@ -34,7 +35,7 @@ class CameraContainerBloc extends EvSourceBlocBase<CameraContainerEvent, CameraC
double _exposureStep = 0.0;
double _currentExposureOffset = 0.0;
double _ev100 = 0.0;
double? _ev100 = 0.0;
CameraContainerBloc(
this._meteringInteractor,
@ -67,12 +68,17 @@ class CameraContainerBloc extends EvSourceBlocBase<CameraContainerEvent, CameraC
@override
void onCommunicationState(communication_states.SourceState communicationState) {
if (communicationState is communication_states.MeasureState) {
_takePhoto().then((ev100Raw) {
if (ev100Raw != null) {
_ev100 = ev100Raw + _meteringInteractor.cameraEvCalibration;
communicationBloc.add(communication_event.MeteringEndedEvent(_ev100));
}
});
if (_canTakePhoto) {
_takePhoto().then((ev100Raw) {
if (ev100Raw != null) {
_ev100 = ev100Raw + _meteringInteractor.cameraEvCalibration;
communicationBloc.add(communication_event.MeteringEndedEvent(_ev100));
} else {
_ev100 = null;
communicationBloc.add(const communication_event.MeteringEndedEvent(null));
}
});
}
}
}
@ -118,7 +124,7 @@ class CameraContainerBloc extends EvSourceBlocBase<CameraContainerEvent, CameraC
_zoomRange = await Future.wait<double>([
_cameraController!.getMinZoomLevel(),
_cameraController!.getMaxZoomLevel(),
]).then((levels) => RangeValues(levels[0], min(_maxZoom, levels[1])));
]).then((levels) => RangeValues(levels[0], math.min(_maxZoom, levels[1])));
_currentZoom = _zoomRange!.start;
_exposureOffsetRange = await Future.wait<double>([
@ -126,8 +132,8 @@ class CameraContainerBloc extends EvSourceBlocBase<CameraContainerEvent, CameraC
_cameraController!.getMaxExposureOffset(),
]).then(
(levels) => RangeValues(
max(_exposureMaxRange.start, levels[0]),
min(_exposureMaxRange.end, levels[1]),
math.max(_exposureMaxRange.start, levels[0]),
math.min(_exposureMaxRange.end, levels[1]),
),
);
await _cameraController!.getExposureOffsetStepSize().then((value) {
@ -172,28 +178,31 @@ class CameraContainerBloc extends EvSourceBlocBase<CameraContainerEvent, CameraC
);
}
Future<double?> _takePhoto() async {
if (_cameraController == null ||
!_cameraController!.value.isInitialized ||
_cameraController!.value.isTakingPicture) {
return null;
}
bool get _canTakePhoto => !(_cameraController == null ||
!_cameraController!.value.isInitialized ||
_cameraController!.value.isTakingPicture);
Future<double?> _takePhoto() async {
try {
final file = await _cameraController!.takePicture();
final Uint8List bytes = await file.readAsBytes();
Directory(file.path).deleteSync(recursive: true);
final tags = await readExifFromBytes(bytes);
final iso = double.parse("${tags["EXIF ISOSpeedRatings"]}");
final apertureValueRatio = (tags["EXIF FNumber"]!.values as IfdRatios).ratios.first;
final iso = double.tryParse("${tags["EXIF ISOSpeedRatings"]}");
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 speedValueRatio = (tags["EXIF ExposureTime"]!.values as IfdRatios).ratios.first;
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) {
debugPrint('Error: ${e.code}\nError Message: ${e.description}');
log('Error: ${e.code}\nError Message: ${e.description}');
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/dialog_picker/widget_picker_dialog.dart';
class AnimatedDialogPicker<T> extends StatelessWidget {
final _key = GlobalKey<AnimatedDialogState>();
// Has to be stateful, so that [GlobalKey] is not recreated.
// Otherwise use will no be able to close the dialog after EV value has changed.
class AnimatedDialogPicker<T> extends StatefulWidget {
final IconData icon;
final String title;
final String? subtitle;
@ -15,7 +16,7 @@ class AnimatedDialogPicker<T> extends StatelessWidget {
final ValueChanged<T> onChanged;
final Widget closedChild;
AnimatedDialogPicker({
const AnimatedDialogPicker({
required this.icon,
required this.title,
this.subtitle,
@ -28,24 +29,31 @@ class AnimatedDialogPicker<T> extends StatelessWidget {
super.key,
});
@override
State<AnimatedDialogPicker<T>> createState() => _AnimatedDialogPickerState<T>();
}
class _AnimatedDialogPickerState<T> extends State<AnimatedDialogPicker<T>> {
final _key = GlobalKey<AnimatedDialogState>();
@override
Widget build(BuildContext context) {
return AnimatedDialog(
key: _key,
closedChild: closedChild,
closedChild: widget.closedChild,
openedChild: DialogPicker<T>(
icon: icon,
title: title,
subtitle: subtitle,
initialValue: selectedValue,
values: values,
itemTitleBuilder: itemTitleBuilder,
itemTrailingBuilder: itemTrailingBuilder,
icon: widget.icon,
title: widget.title,
subtitle: widget.subtitle,
initialValue: widget.selectedValue,
values: widget.values,
itemTitleBuilder: widget.itemTitleBuilder,
itemTrailingBuilder: widget.itemTrailingBuilder,
onCancel: () {
_key.currentState?.close();
},
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: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 {
final ExposurePair? fastest;
final ExposurePair? slowest;

View file

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

View file

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

View file

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

View file

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

View file

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