This commit is contained in:
Vadim 2023-03-17 21:24:07 +03:00
parent c5179e71ea
commit 284e95854d
7 changed files with 62 additions and 76 deletions

View file

@ -8,6 +8,7 @@ import 'package:lightmeter/data/caffeine_service.dart';
import 'package:lightmeter/data/haptics_service.dart';
import 'package:lightmeter/data/models/supported_locale.dart';
import 'package:lightmeter/providers/supported_locale_provider.dart';
import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
@ -47,6 +48,7 @@ class Application extends StatelessWidget {
Provider(create: (_) => PermissionsService()),
Provider(create: (_) => const LightSensorService()),
],
child: IAPProductsProvider(
child: StopTypeProvider(
child: EquipmentProfileProvider(
child: EvSourceTypeProvider(
@ -79,6 +81,7 @@ class Application extends StatelessWidget {
),
),
),
),
);
}
return const SizedBox();

View file

@ -15,17 +15,18 @@ class EquipmentProfileProvider extends StatefulWidget {
}
class EquipmentProfileProviderState extends State<EquipmentProfileProvider> {
final List<EquipmentProfileData> _profiles = [
const EquipmentProfileData(
id: '0',
name: 'Default',
final List<EquipmentProfileData> _profiles = [];
late EquipmentProfileData _selectedProfile = _profiles.isNotEmpty
? _profiles.first
: const EquipmentProfileData(
id: 'default',
name: '',
apertureValues: apertureValues,
ndValues: ndValues,
shutterSpeedValues: shutterSpeedValues,
isoValues: isoValues,
),
];
late EquipmentProfileData? _selectedProfile = _profiles.isNotEmpty ? _profiles.first : null;
);
@override
Widget build(BuildContext context) {
@ -77,8 +78,12 @@ class EquipmentProfile extends InheritedWidget {
super.key,
});
static EquipmentProfileData? of(BuildContext context) {
static EquipmentProfileData? of(BuildContext context, {bool listen = true}) {
if (listen) {
return context.dependOnInheritedWidgetOfExactType<EquipmentProfile>()?.data;
} else {
return context.findAncestorWidgetOfExactType<EquipmentProfile>()?.data;
}
}
@override

View file

@ -21,9 +21,12 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
final MeteringInteractor _meteringInteractor;
late final StreamSubscription<communication_states.ScreenState> _communicationSubscription;
List<ApertureValue> get _apertureValues => apertureValues.whereStopType(stopType);
List<ShutterSpeedValue> get _shutterSpeedValues => shutterSpeedValues.whereStopType(stopType);
List<ApertureValue> get _apertureValues =>
_equipmentProfileData.apertureValues.whereStopType(stopType);
List<ShutterSpeedValue> get _shutterSpeedValues =>
_equipmentProfileData.shutterSpeedValues.whereStopType(stopType);
EquipmentProfileData _equipmentProfileData;
StopType stopType;
late IsoValue _iso = _userPreferencesService.iso;
@ -35,6 +38,7 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
this._communicationBloc,
this._userPreferencesService,
this._meteringInteractor,
this._equipmentProfileData,
this.stopType,
) : super(
MeteringEndedState(
@ -76,6 +80,8 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
}
void _onEquipmentProfileChanged(EquipmentProfileChangedEvent event, Emitter emit) {
_equipmentProfileData = event.equipmentProfileData;
/// Update selected ISO value, if selected equipment profile
/// doesn't contain currently selected value
if (!event.equipmentProfileData.isoValues.any((v) => _iso.value == v.value)) {
@ -90,6 +96,7 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
_ev = _ev - event.equipmentProfileData.ndValues.first.stopReduction + _nd.stopReduction;
_nd = event.equipmentProfileData.ndValues.first;
}
_emitMeasuredState(emit);
}

View file

@ -2,8 +2,8 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:lightmeter/data/models/exposure_pair.dart';
import 'package:lightmeter/interactors/metering_interactor.dart';
import 'package:lightmeter/providers/equipment_profile_provider.dart';
import 'package:lightmeter/screens/metering/communication/bloc_communication_metering.dart';
import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
import 'bloc_container_camera.dart';

View file

@ -2,8 +2,8 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:lightmeter/data/models/exposure_pair.dart';
import 'package:lightmeter/interactors/metering_interactor.dart';
import 'package:lightmeter/providers/equipment_profile_provider.dart';
import 'package:lightmeter/screens/metering/communication/bloc_communication_metering.dart';
import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
import 'bloc_container_light_sensor.dart';

View file

@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:lightmeter/data/models/exposure_pair.dart';
import 'package:lightmeter/generated/l10n.dart';
import 'package:lightmeter/providers/equipment_profile_provider.dart';
import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
import 'components/animated_dialog_picker/widget_dialog_animated_picker.dart';
@ -37,11 +38,12 @@ class ReadingsContainer extends StatelessWidget {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (EquipmentProfiles.of(context)!.isNotEmpty) ...[
if (IAPProducts.of(context, IAPProductType.equipment)?.status ==
IAPProductStatus.purchased) ...[
ReadingValueContainer.singleValue(
value: ReadingValue(
label: S.of(context).equipment,
value: 'Parktica + Zenitar',
value: EquipmentProfile.of(context)!.name,
),
),
const _InnerPadding(),
@ -87,39 +89,6 @@ class _InnerPadding extends SizedBox {
const _InnerPadding() : super(height: Dimens.grid8, width: Dimens.grid8);
}
class _EquipmentProfileDataTile extends StatelessWidget {
final List<IsoValue> values;
final IsoValue selectedValue;
final ValueChanged<IsoValue> onChanged;
const _EquipmentProfileDataTile({
required this.selectedValue,
required this.values,
required this.onChanged,
});
@override
Widget build(BuildContext context) {
return AnimatedDialogPicker<IsoValue>(
title: S.of(context).iso,
subtitle: S.of(context).filmSpeed,
selectedValue: selectedValue,
values: values,
itemTitleBuilder: (_, value) => Text(value.value.toString()),
// using ascending order, because increase in film speed rises EV
evDifferenceBuilder: (selected, other) => selected.toStringDifference(other),
onChanged: onChanged,
closedChild: ReadingValueContainer.singleValue(
value: ReadingValue(
label: S.of(context).iso,
value: selectedValue.value.toString(),
),
),
);
}
}
class _IsoValueTile extends StatelessWidget {
final List<IsoValue> values;
final IsoValue selectedValue;

View file

@ -6,6 +6,7 @@ import 'package:lightmeter/data/light_sensor_service.dart';
import 'package:lightmeter/data/permissions_service.dart';
import 'package:lightmeter/data/shared_prefs_service.dart';
import 'package:lightmeter/interactors/metering_interactor.dart';
import 'package:lightmeter/providers/equipment_profile_provider.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
import 'package:provider/provider.dart';
@ -39,6 +40,7 @@ class _MeteringFlowState extends State<MeteringFlow> {
context.read<MeteringCommunicationBloc>(),
context.read<UserPreferencesService>(),
context.read<MeteringInteractor>(),
EquipmentProfile.of(context, listen: false)!,
context.read<StopType>(),
),
),