diff --git a/lib/application.dart b/lib/application.dart index ed596a5..0f0a184 100644 --- a/lib/application.dart +++ b/lib/application.dart @@ -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,31 +48,33 @@ class Application extends StatelessWidget { Provider(create: (_) => PermissionsService()), Provider(create: (_) => const LightSensorService()), ], - child: StopTypeProvider( - child: EquipmentProfileProvider( - child: EvSourceTypeProvider( - child: SupportedLocaleProvider( - child: ThemeProvider( - builder: (context, _) => _AnnotatedRegionWrapper( - child: MaterialApp( - theme: context.watch(), - locale: Locale(context.watch().intlName), - localizationsDelegates: const [ - S.delegate, - GlobalMaterialLocalizations.delegate, - GlobalWidgetsLocalizations.delegate, - GlobalCupertinoLocalizations.delegate, - ], - supportedLocales: S.delegate.supportedLocales, - builder: (context, child) => MediaQuery( - data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0), - child: child!, + child: IAPProductsProvider( + child: StopTypeProvider( + child: EquipmentProfileProvider( + child: EvSourceTypeProvider( + child: SupportedLocaleProvider( + child: ThemeProvider( + builder: (context, _) => _AnnotatedRegionWrapper( + child: MaterialApp( + theme: context.watch(), + locale: Locale(context.watch().intlName), + localizationsDelegates: const [ + S.delegate, + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + GlobalCupertinoLocalizations.delegate, + ], + supportedLocales: S.delegate.supportedLocales, + builder: (context, child) => MediaQuery( + data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0), + child: child!, + ), + initialRoute: "metering", + routes: { + "metering": (context) => const MeteringFlow(), + "settings": (context) => const SettingsFlow(), + }, ), - initialRoute: "metering", - routes: { - "metering": (context) => const MeteringFlow(), - "settings": (context) => const SettingsFlow(), - }, ), ), ), diff --git a/lib/providers/equipment_profile_provider.dart b/lib/providers/equipment_profile_provider.dart index 7f3f6be..2a67161 100644 --- a/lib/providers/equipment_profile_provider.dart +++ b/lib/providers/equipment_profile_provider.dart @@ -15,17 +15,18 @@ class EquipmentProfileProvider extends StatefulWidget { } class EquipmentProfileProviderState extends State { - final List _profiles = [ - const EquipmentProfileData( - id: '0', - name: 'Default', - apertureValues: apertureValues, - ndValues: ndValues, - shutterSpeedValues: shutterSpeedValues, - isoValues: isoValues, - ), - ]; - late EquipmentProfileData? _selectedProfile = _profiles.isNotEmpty ? _profiles.first : null; + final List _profiles = []; + + late EquipmentProfileData _selectedProfile = _profiles.isNotEmpty + ? _profiles.first + : const EquipmentProfileData( + id: 'default', + name: '', + apertureValues: apertureValues, + ndValues: ndValues, + shutterSpeedValues: shutterSpeedValues, + isoValues: isoValues, + ); @override Widget build(BuildContext context) { @@ -77,8 +78,12 @@ class EquipmentProfile extends InheritedWidget { super.key, }); - static EquipmentProfileData? of(BuildContext context) { - return context.dependOnInheritedWidgetOfExactType()?.data; + static EquipmentProfileData? of(BuildContext context, {bool listen = true}) { + if (listen) { + return context.dependOnInheritedWidgetOfExactType()?.data; + } else { + return context.findAncestorWidgetOfExactType()?.data; + } } @override diff --git a/lib/screens/metering/bloc_metering.dart b/lib/screens/metering/bloc_metering.dart index d351cdf..01ce00e 100644 --- a/lib/screens/metering/bloc_metering.dart +++ b/lib/screens/metering/bloc_metering.dart @@ -21,9 +21,12 @@ class MeteringBloc extends Bloc { final MeteringInteractor _meteringInteractor; late final StreamSubscription _communicationSubscription; - List get _apertureValues => apertureValues.whereStopType(stopType); - List get _shutterSpeedValues => shutterSpeedValues.whereStopType(stopType); + List get _apertureValues => + _equipmentProfileData.apertureValues.whereStopType(stopType); + List get _shutterSpeedValues => + _equipmentProfileData.shutterSpeedValues.whereStopType(stopType); + EquipmentProfileData _equipmentProfileData; StopType stopType; late IsoValue _iso = _userPreferencesService.iso; @@ -35,6 +38,7 @@ class MeteringBloc extends Bloc { this._communicationBloc, this._userPreferencesService, this._meteringInteractor, + this._equipmentProfileData, this.stopType, ) : super( MeteringEndedState( @@ -76,6 +80,8 @@ class MeteringBloc extends Bloc { } 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 { _ev = _ev - event.equipmentProfileData.ndValues.first.stopReduction + _nd.stopReduction; _nd = event.equipmentProfileData.ndValues.first; } + _emitMeasuredState(emit); } diff --git a/lib/screens/metering/components/camera_container/provider_container_camera.dart b/lib/screens/metering/components/camera_container/provider_container_camera.dart index a5aab1c..d1775ea 100644 --- a/lib/screens/metering/components/camera_container/provider_container_camera.dart +++ b/lib/screens/metering/components/camera_container/provider_container_camera.dart @@ -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'; diff --git a/lib/screens/metering/components/light_sensor_container/provider_container_light_sensor.dart b/lib/screens/metering/components/light_sensor_container/provider_container_light_sensor.dart index c7072b5..7c71de3 100644 --- a/lib/screens/metering/components/light_sensor_container/provider_container_light_sensor.dart +++ b/lib/screens/metering/components/light_sensor_container/provider_container_light_sensor.dart @@ -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'; diff --git a/lib/screens/metering/components/shared/readings_container/widget_container_readings.dart b/lib/screens/metering/components/shared/readings_container/widget_container_readings.dart index 97071c3..15afdb9 100644 --- a/lib/screens/metering/components/shared/readings_container/widget_container_readings.dart +++ b/lib/screens/metering/components/shared/readings_container/widget_container_readings.dart @@ -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 values; - final IsoValue selectedValue; - final ValueChanged onChanged; - - const _EquipmentProfileDataTile({ - required this.selectedValue, - required this.values, - required this.onChanged, - }); - - @override - Widget build(BuildContext context) { - return AnimatedDialogPicker( - 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 values; final IsoValue selectedValue; diff --git a/lib/screens/metering/flow_metering.dart b/lib/screens/metering/flow_metering.dart index c064391..1df6b83 100644 --- a/lib/screens/metering/flow_metering.dart +++ b/lib/screens/metering/flow_metering.dart @@ -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 { context.read(), context.read(), context.read(), + EquipmentProfile.of(context, listen: false)!, context.read(), ), ),