From 86c7a9c839ef55279ba3ceee053e2299ca5a1cf8 Mon Sep 17 00:00:00 2001 From: Vadim <44135514+vodemn@users.noreply.github.com> Date: Fri, 3 Mar 2023 18:12:27 +0300 Subject: [PATCH] get iso & nd values from equipment profile --- lib/application.dart | 47 +++++----- lib/data/models/equipment_profile_data.dart | 22 +++++ lib/providers/equipment_profile_provider.dart | 90 +++++++++++++++++++ .../provider_container_camera.dart | 3 + .../widget_container_camera.dart | 6 ++ .../provider_container_light_sensor.dart | 3 + .../widget_container_light_sensor.dart | 6 ++ .../widget_container_readings.dart | 40 ++++++--- 8 files changed, 183 insertions(+), 34 deletions(-) create mode 100644 lib/data/models/equipment_profile_data.dart create mode 100644 lib/providers/equipment_profile_provider.dart diff --git a/lib/application.dart b/lib/application.dart index f7ca38e..ed596a5 100644 --- a/lib/application.dart +++ b/lib/application.dart @@ -16,6 +16,7 @@ import 'data/permissions_service.dart'; import 'data/shared_prefs_service.dart'; import 'environment.dart'; import 'generated/l10n.dart'; +import 'providers/equipment_profile_provider.dart'; import 'providers/ev_source_type_provider.dart'; import 'providers/theme_provider.dart'; import 'screens/metering/flow_metering.dart'; @@ -47,29 +48,31 @@ class Application extends StatelessWidget { Provider(create: (_) => const LightSensorService()), ], child: StopTypeProvider( - 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: 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/data/models/equipment_profile_data.dart b/lib/data/models/equipment_profile_data.dart new file mode 100644 index 0000000..dede472 --- /dev/null +++ b/lib/data/models/equipment_profile_data.dart @@ -0,0 +1,22 @@ +import 'package:lightmeter/data/models/photography_values/aperture_value.dart'; +import 'package:lightmeter/data/models/photography_values/iso_value.dart'; +import 'package:lightmeter/data/models/photography_values/nd_value.dart'; +import 'package:lightmeter/data/models/photography_values/shutter_speed_value.dart'; + +class EquipmentProfileData { + final String id; + final String name; + final List apertureValues; + final List ndValues; + final List shutterSpeedValues; + final List isoValues; + + const EquipmentProfileData({ + required this.id, + required this.name, + required this.apertureValues, + required this.ndValues, + required this.shutterSpeedValues, + required this.isoValues, + }); +} diff --git a/lib/providers/equipment_profile_provider.dart b/lib/providers/equipment_profile_provider.dart new file mode 100644 index 0000000..9d12f2f --- /dev/null +++ b/lib/providers/equipment_profile_provider.dart @@ -0,0 +1,90 @@ +import 'package:flutter/material.dart'; +import 'package:lightmeter/data/models/equipment_profile_data.dart'; +import 'package:lightmeter/data/models/photography_values/aperture_value.dart'; +import 'package:lightmeter/data/models/photography_values/iso_value.dart'; +import 'package:lightmeter/data/models/photography_values/nd_value.dart'; +import 'package:lightmeter/data/models/photography_values/shutter_speed_value.dart'; + +class EquipmentProfileProvider extends StatefulWidget { + final Widget child; + + const EquipmentProfileProvider({required this.child, super.key}); + + static EquipmentProfileProviderState of(BuildContext context) { + return context.findAncestorStateOfType()!; + } + + @override + State createState() => EquipmentProfileProviderState(); +} + +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; + + @override + Widget build(BuildContext context) { + return EquipmentProfiles( + profiles: _profiles, + child: EquipmentProfile( + data: _selectedProfile, + child: widget.child, + ), + ); + } + + void setProfile(EquipmentProfileData data) { + setState(() { + _selectedProfile = data; + }); + } + + void addProfile(EquipmentProfileData data) {} + + void updateProdile(EquipmentProfileData data) {} + + void deleteProfile(EquipmentProfileData data) {} +} + +class EquipmentProfiles extends InheritedWidget { + final List profiles; + + const EquipmentProfiles({ + required this.profiles, + required super.child, + super.key, + }); + + static List? of(BuildContext context) { + return context.dependOnInheritedWidgetOfExactType()?.profiles; + } + + @override + bool updateShouldNotify(EquipmentProfiles oldWidget) => true; +} + +class EquipmentProfile extends InheritedWidget { + final EquipmentProfileData? data; + + const EquipmentProfile({ + required this.data, + required super.child, + super.key, + }); + + static EquipmentProfileData? of(BuildContext context) { + return context.dependOnInheritedWidgetOfExactType()?.data; + } + + @override + bool updateShouldNotify(EquipmentProfile oldWidget) => true; +} 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 729322e..3365622 100644 --- a/lib/screens/metering/components/camera_container/provider_container_camera.dart +++ b/lib/screens/metering/components/camera_container/provider_container_camera.dart @@ -4,6 +4,7 @@ import 'package:lightmeter/data/models/exposure_pair.dart'; import 'package:lightmeter/data/models/photography_values/iso_value.dart'; import 'package:lightmeter/data/models/photography_values/nd_value.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 'bloc_container_camera.dart'; @@ -40,7 +41,9 @@ class CameraContainerProvider extends StatelessWidget { child: CameraContainer( fastest: fastest, slowest: slowest, + isoValues: EquipmentProfile.of(context)?.isoValues ?? isoValues, iso: iso, + ndValues: EquipmentProfile.of(context)?.ndValues ?? ndValues, nd: nd, onIsoChanged: onIsoChanged, onNdChanged: onNdChanged, diff --git a/lib/screens/metering/components/camera_container/widget_container_camera.dart b/lib/screens/metering/components/camera_container/widget_container_camera.dart index 34906aa..998c4df 100644 --- a/lib/screens/metering/components/camera_container/widget_container_camera.dart +++ b/lib/screens/metering/components/camera_container/widget_container_camera.dart @@ -21,7 +21,9 @@ import 'state_container_camera.dart'; class CameraContainer extends StatelessWidget { final ExposurePair? fastest; final ExposurePair? slowest; + final List isoValues; final IsoValue iso; + final List ndValues; final NdValue nd; final ValueChanged onIsoChanged; final ValueChanged onNdChanged; @@ -30,7 +32,9 @@ class CameraContainer extends StatelessWidget { const CameraContainer({ required this.fastest, required this.slowest, + required this.isoValues, required this.iso, + required this.ndValues, required this.nd, required this.onIsoChanged, required this.onNdChanged, @@ -49,7 +53,9 @@ class CameraContainer extends StatelessWidget { readingsContainer: ReadingsContainer( fastest: fastest, slowest: slowest, + isoValues: isoValues, iso: iso, + ndValues: ndValues, nd: nd, onIsoChanged: onIsoChanged, onNdChanged: onNdChanged, 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 5d75647..8734233 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 @@ -4,6 +4,7 @@ import 'package:lightmeter/data/models/exposure_pair.dart'; import 'package:lightmeter/data/models/photography_values/iso_value.dart'; import 'package:lightmeter/data/models/photography_values/nd_value.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 'bloc_container_light_sensor.dart'; @@ -40,7 +41,9 @@ class LightSensorContainerProvider extends StatelessWidget { child: LightSensorContainer( fastest: fastest, slowest: slowest, + isoValues: EquipmentProfile.of(context)?.isoValues ?? isoValues, iso: iso, + ndValues: EquipmentProfile.of(context)?.ndValues ?? ndValues, nd: nd, onIsoChanged: onIsoChanged, onNdChanged: onNdChanged, diff --git a/lib/screens/metering/components/light_sensor_container/widget_container_light_sensor.dart b/lib/screens/metering/components/light_sensor_container/widget_container_light_sensor.dart index e8019d0..bd1cc95 100644 --- a/lib/screens/metering/components/light_sensor_container/widget_container_light_sensor.dart +++ b/lib/screens/metering/components/light_sensor_container/widget_container_light_sensor.dart @@ -10,7 +10,9 @@ import 'package:lightmeter/screens/metering/components/shared/readings_container class LightSensorContainer extends StatelessWidget { final ExposurePair? fastest; final ExposurePair? slowest; + final List isoValues; final IsoValue iso; + final List ndValues; final NdValue nd; final ValueChanged onIsoChanged; final ValueChanged onNdChanged; @@ -19,7 +21,9 @@ class LightSensorContainer extends StatelessWidget { const LightSensorContainer({ required this.fastest, required this.slowest, + required this.isoValues, required this.iso, + required this.ndValues, required this.nd, required this.onIsoChanged, required this.onNdChanged, @@ -35,7 +39,9 @@ class LightSensorContainer extends StatelessWidget { readingsContainer: ReadingsContainer( fastest: fastest, slowest: slowest, + isoValues: isoValues, iso: iso, + ndValues: ndValues, nd: nd, onIsoChanged: onIsoChanged, onNdChanged: onNdChanged, 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 9815034..a24d2a7 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 @@ -12,7 +12,9 @@ import 'components/reading_value_container/widget_container_reading_value.dart'; class ReadingsContainer extends StatelessWidget { final ExposurePair? fastest; final ExposurePair? slowest; + final List isoValues; final IsoValue iso; + final List ndValues; final NdValue nd; final ValueChanged onIsoChanged; final ValueChanged onNdChanged; @@ -20,7 +22,9 @@ class ReadingsContainer extends StatelessWidget { const ReadingsContainer({ required this.fastest, required this.slowest, + required this.isoValues, required this.iso, + required this.ndValues, required this.nd, required this.onIsoChanged, required this.onNdChanged, @@ -49,14 +53,16 @@ class ReadingsContainer extends StatelessWidget { children: [ Expanded( child: _IsoValueTile( - value: iso, + selectedValue: iso, + values: isoValues, onChanged: onIsoChanged, ), ), const _InnerPadding(), Expanded( child: _NdValueTile( - value: nd, + selectedValue: nd, + values: ndValues, onChanged: onNdChanged, ), ), @@ -72,18 +78,23 @@ class _InnerPadding extends SizedBox { } class _IsoValueTile extends StatelessWidget { - final IsoValue value; + final List values; + final IsoValue selectedValue; final ValueChanged onChanged; - const _IsoValueTile({required this.value, required this.onChanged}); + const _IsoValueTile({ + 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: value, - values: isoValues, + 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), @@ -91,7 +102,7 @@ class _IsoValueTile extends StatelessWidget { closedChild: ReadingValueContainer.singleValue( value: ReadingValue( label: S.of(context).iso, - value: value.value.toString(), + value: selectedValue.value.toString(), ), ), ); @@ -99,18 +110,23 @@ class _IsoValueTile extends StatelessWidget { } class _NdValueTile extends StatelessWidget { - final NdValue value; + final List values; + final NdValue selectedValue; final ValueChanged onChanged; - const _NdValueTile({required this.value, required this.onChanged}); + const _NdValueTile({ + required this.selectedValue, + required this.values, + required this.onChanged, + }); @override Widget build(BuildContext context) { return AnimatedDialogPicker( title: S.of(context).nd, subtitle: S.of(context).ndFilterFactor, - selectedValue: value, - values: ndValues, + selectedValue: selectedValue, + values: values, itemTitleBuilder: (_, value) => Text( value.value == 0 ? S.of(context).none : value.value.toString(), ), @@ -120,7 +136,7 @@ class _NdValueTile extends StatelessWidget { closedChild: ReadingValueContainer.singleValue( value: ReadingValue( label: S.of(context).nd, - value: value.value.toString(), + value: selectedValue.value.toString(), ), ), );