get iso & nd values from equipment profile

This commit is contained in:
Vadim 2023-03-03 18:12:27 +03:00
parent b160ff6ad0
commit 86c7a9c839
8 changed files with 183 additions and 34 deletions

View file

@ -16,6 +16,7 @@ import 'data/permissions_service.dart';
import 'data/shared_prefs_service.dart'; import 'data/shared_prefs_service.dart';
import 'environment.dart'; import 'environment.dart';
import 'generated/l10n.dart'; import 'generated/l10n.dart';
import 'providers/equipment_profile_provider.dart';
import 'providers/ev_source_type_provider.dart'; import 'providers/ev_source_type_provider.dart';
import 'providers/theme_provider.dart'; import 'providers/theme_provider.dart';
import 'screens/metering/flow_metering.dart'; import 'screens/metering/flow_metering.dart';
@ -47,29 +48,31 @@ class Application extends StatelessWidget {
Provider(create: (_) => const LightSensorService()), Provider(create: (_) => const LightSensorService()),
], ],
child: StopTypeProvider( child: StopTypeProvider(
child: EvSourceTypeProvider( child: EquipmentProfileProvider(
child: SupportedLocaleProvider( child: EvSourceTypeProvider(
child: ThemeProvider( child: SupportedLocaleProvider(
builder: (context, _) => _AnnotatedRegionWrapper( child: ThemeProvider(
child: MaterialApp( builder: (context, _) => _AnnotatedRegionWrapper(
theme: context.watch<ThemeData>(), child: MaterialApp(
locale: Locale(context.watch<SupportedLocale>().intlName), theme: context.watch<ThemeData>(),
localizationsDelegates: const [ locale: Locale(context.watch<SupportedLocale>().intlName),
S.delegate, localizationsDelegates: const [
GlobalMaterialLocalizations.delegate, S.delegate,
GlobalWidgetsLocalizations.delegate, GlobalMaterialLocalizations.delegate,
GlobalCupertinoLocalizations.delegate, GlobalWidgetsLocalizations.delegate,
], GlobalCupertinoLocalizations.delegate,
supportedLocales: S.delegate.supportedLocales, ],
builder: (context, child) => MediaQuery( supportedLocales: S.delegate.supportedLocales,
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0), builder: (context, child) => MediaQuery(
child: child!, 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(),
},
), ),
), ),
), ),

View file

@ -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<ApertureValue> apertureValues;
final List<NdValue> ndValues;
final List<ShutterSpeedValue> shutterSpeedValues;
final List<IsoValue> isoValues;
const EquipmentProfileData({
required this.id,
required this.name,
required this.apertureValues,
required this.ndValues,
required this.shutterSpeedValues,
required this.isoValues,
});
}

View file

@ -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<EquipmentProfileProviderState>()!;
}
@override
State<EquipmentProfileProvider> createState() => EquipmentProfileProviderState();
}
class EquipmentProfileProviderState extends State<EquipmentProfileProvider> {
final List<EquipmentProfileData> _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<EquipmentProfileData> profiles;
const EquipmentProfiles({
required this.profiles,
required super.child,
super.key,
});
static List<EquipmentProfileData>? of(BuildContext context) {
return context.dependOnInheritedWidgetOfExactType<EquipmentProfiles>()?.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<EquipmentProfile>()?.data;
}
@override
bool updateShouldNotify(EquipmentProfile oldWidget) => true;
}

View file

@ -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/iso_value.dart';
import 'package:lightmeter/data/models/photography_values/nd_value.dart'; import 'package:lightmeter/data/models/photography_values/nd_value.dart';
import 'package:lightmeter/interactors/metering_interactor.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:lightmeter/screens/metering/communication/bloc_communication_metering.dart';
import 'bloc_container_camera.dart'; import 'bloc_container_camera.dart';
@ -40,7 +41,9 @@ class CameraContainerProvider extends StatelessWidget {
child: CameraContainer( child: CameraContainer(
fastest: fastest, fastest: fastest,
slowest: slowest, slowest: slowest,
isoValues: EquipmentProfile.of(context)?.isoValues ?? isoValues,
iso: iso, iso: iso,
ndValues: EquipmentProfile.of(context)?.ndValues ?? ndValues,
nd: nd, nd: nd,
onIsoChanged: onIsoChanged, onIsoChanged: onIsoChanged,
onNdChanged: onNdChanged, onNdChanged: onNdChanged,

View file

@ -21,7 +21,9 @@ import 'state_container_camera.dart';
class CameraContainer extends StatelessWidget { class CameraContainer extends StatelessWidget {
final ExposurePair? fastest; final ExposurePair? fastest;
final ExposurePair? slowest; final ExposurePair? slowest;
final List<IsoValue> isoValues;
final IsoValue iso; final IsoValue iso;
final List<NdValue> ndValues;
final NdValue nd; final NdValue nd;
final ValueChanged<IsoValue> onIsoChanged; final ValueChanged<IsoValue> onIsoChanged;
final ValueChanged<NdValue> onNdChanged; final ValueChanged<NdValue> onNdChanged;
@ -30,7 +32,9 @@ class CameraContainer extends StatelessWidget {
const CameraContainer({ const CameraContainer({
required this.fastest, required this.fastest,
required this.slowest, required this.slowest,
required this.isoValues,
required this.iso, required this.iso,
required this.ndValues,
required this.nd, required this.nd,
required this.onIsoChanged, required this.onIsoChanged,
required this.onNdChanged, required this.onNdChanged,
@ -49,7 +53,9 @@ class CameraContainer extends StatelessWidget {
readingsContainer: ReadingsContainer( readingsContainer: ReadingsContainer(
fastest: fastest, fastest: fastest,
slowest: slowest, slowest: slowest,
isoValues: isoValues,
iso: iso, iso: iso,
ndValues: ndValues,
nd: nd, nd: nd,
onIsoChanged: onIsoChanged, onIsoChanged: onIsoChanged,
onNdChanged: onNdChanged, onNdChanged: onNdChanged,

View file

@ -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/iso_value.dart';
import 'package:lightmeter/data/models/photography_values/nd_value.dart'; import 'package:lightmeter/data/models/photography_values/nd_value.dart';
import 'package:lightmeter/interactors/metering_interactor.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:lightmeter/screens/metering/communication/bloc_communication_metering.dart';
import 'bloc_container_light_sensor.dart'; import 'bloc_container_light_sensor.dart';
@ -40,7 +41,9 @@ class LightSensorContainerProvider extends StatelessWidget {
child: LightSensorContainer( child: LightSensorContainer(
fastest: fastest, fastest: fastest,
slowest: slowest, slowest: slowest,
isoValues: EquipmentProfile.of(context)?.isoValues ?? isoValues,
iso: iso, iso: iso,
ndValues: EquipmentProfile.of(context)?.ndValues ?? ndValues,
nd: nd, nd: nd,
onIsoChanged: onIsoChanged, onIsoChanged: onIsoChanged,
onNdChanged: onNdChanged, onNdChanged: onNdChanged,

View file

@ -10,7 +10,9 @@ import 'package:lightmeter/screens/metering/components/shared/readings_container
class LightSensorContainer extends StatelessWidget { class LightSensorContainer extends StatelessWidget {
final ExposurePair? fastest; final ExposurePair? fastest;
final ExposurePair? slowest; final ExposurePair? slowest;
final List<IsoValue> isoValues;
final IsoValue iso; final IsoValue iso;
final List<NdValue> ndValues;
final NdValue nd; final NdValue nd;
final ValueChanged<IsoValue> onIsoChanged; final ValueChanged<IsoValue> onIsoChanged;
final ValueChanged<NdValue> onNdChanged; final ValueChanged<NdValue> onNdChanged;
@ -19,7 +21,9 @@ class LightSensorContainer extends StatelessWidget {
const LightSensorContainer({ const LightSensorContainer({
required this.fastest, required this.fastest,
required this.slowest, required this.slowest,
required this.isoValues,
required this.iso, required this.iso,
required this.ndValues,
required this.nd, required this.nd,
required this.onIsoChanged, required this.onIsoChanged,
required this.onNdChanged, required this.onNdChanged,
@ -35,7 +39,9 @@ class LightSensorContainer extends StatelessWidget {
readingsContainer: ReadingsContainer( readingsContainer: ReadingsContainer(
fastest: fastest, fastest: fastest,
slowest: slowest, slowest: slowest,
isoValues: isoValues,
iso: iso, iso: iso,
ndValues: ndValues,
nd: nd, nd: nd,
onIsoChanged: onIsoChanged, onIsoChanged: onIsoChanged,
onNdChanged: onNdChanged, onNdChanged: onNdChanged,

View file

@ -12,7 +12,9 @@ import 'components/reading_value_container/widget_container_reading_value.dart';
class ReadingsContainer extends StatelessWidget { class ReadingsContainer extends StatelessWidget {
final ExposurePair? fastest; final ExposurePair? fastest;
final ExposurePair? slowest; final ExposurePair? slowest;
final List<IsoValue> isoValues;
final IsoValue iso; final IsoValue iso;
final List<NdValue> ndValues;
final NdValue nd; final NdValue nd;
final ValueChanged<IsoValue> onIsoChanged; final ValueChanged<IsoValue> onIsoChanged;
final ValueChanged<NdValue> onNdChanged; final ValueChanged<NdValue> onNdChanged;
@ -20,7 +22,9 @@ class ReadingsContainer extends StatelessWidget {
const ReadingsContainer({ const ReadingsContainer({
required this.fastest, required this.fastest,
required this.slowest, required this.slowest,
required this.isoValues,
required this.iso, required this.iso,
required this.ndValues,
required this.nd, required this.nd,
required this.onIsoChanged, required this.onIsoChanged,
required this.onNdChanged, required this.onNdChanged,
@ -49,14 +53,16 @@ class ReadingsContainer extends StatelessWidget {
children: [ children: [
Expanded( Expanded(
child: _IsoValueTile( child: _IsoValueTile(
value: iso, selectedValue: iso,
values: isoValues,
onChanged: onIsoChanged, onChanged: onIsoChanged,
), ),
), ),
const _InnerPadding(), const _InnerPadding(),
Expanded( Expanded(
child: _NdValueTile( child: _NdValueTile(
value: nd, selectedValue: nd,
values: ndValues,
onChanged: onNdChanged, onChanged: onNdChanged,
), ),
), ),
@ -72,18 +78,23 @@ class _InnerPadding extends SizedBox {
} }
class _IsoValueTile extends StatelessWidget { class _IsoValueTile extends StatelessWidget {
final IsoValue value; final List<IsoValue> values;
final IsoValue selectedValue;
final ValueChanged<IsoValue> onChanged; final ValueChanged<IsoValue> onChanged;
const _IsoValueTile({required this.value, required this.onChanged}); const _IsoValueTile({
required this.selectedValue,
required this.values,
required this.onChanged,
});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return AnimatedDialogPicker<IsoValue>( return AnimatedDialogPicker<IsoValue>(
title: S.of(context).iso, title: S.of(context).iso,
subtitle: S.of(context).filmSpeed, subtitle: S.of(context).filmSpeed,
selectedValue: value, selectedValue: selectedValue,
values: isoValues, values: values,
itemTitleBuilder: (_, value) => Text(value.value.toString()), itemTitleBuilder: (_, value) => Text(value.value.toString()),
// using ascending order, because increase in film speed rises EV // using ascending order, because increase in film speed rises EV
evDifferenceBuilder: (selected, other) => selected.toStringDifference(other), evDifferenceBuilder: (selected, other) => selected.toStringDifference(other),
@ -91,7 +102,7 @@ class _IsoValueTile extends StatelessWidget {
closedChild: ReadingValueContainer.singleValue( closedChild: ReadingValueContainer.singleValue(
value: ReadingValue( value: ReadingValue(
label: S.of(context).iso, 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 { class _NdValueTile extends StatelessWidget {
final NdValue value; final List<NdValue> values;
final NdValue selectedValue;
final ValueChanged<NdValue> onChanged; final ValueChanged<NdValue> onChanged;
const _NdValueTile({required this.value, required this.onChanged}); const _NdValueTile({
required this.selectedValue,
required this.values,
required this.onChanged,
});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return AnimatedDialogPicker<NdValue>( return AnimatedDialogPicker<NdValue>(
title: S.of(context).nd, title: S.of(context).nd,
subtitle: S.of(context).ndFilterFactor, subtitle: S.of(context).ndFilterFactor,
selectedValue: value, selectedValue: selectedValue,
values: ndValues, values: values,
itemTitleBuilder: (_, value) => Text( itemTitleBuilder: (_, value) => Text(
value.value == 0 ? S.of(context).none : value.value.toString(), value.value == 0 ? S.of(context).none : value.value.toString(),
), ),
@ -120,7 +136,7 @@ class _NdValueTile extends StatelessWidget {
closedChild: ReadingValueContainer.singleValue( closedChild: ReadingValueContainer.singleValue(
value: ReadingValue( value: ReadingValue(
label: S.of(context).nd, label: S.of(context).nd,
value: value.value.toString(), value: selectedValue.value.toString(),
), ),
), ),
); );