From ce4af92b4dbceaf2905361a4b59ea50dba18f898 Mon Sep 17 00:00:00 2001 From: Vadim Date: Thu, 23 Mar 2023 23:12:14 +0300 Subject: [PATCH] filter equipment profile update/delete --- lib/providers/equipment_profile_provider.dart | 6 ++++++ .../camera_container/provider_container_camera.dart | 3 --- .../camera_container/widget_container_camera.dart | 3 --- .../provider_container_light_sensor.dart | 3 --- .../widget_container_light_sensor.dart | 3 --- .../readings_container/widget_container_readings.dart | 7 +------ lib/screens/metering/screen_metering.dart | 8 ++------ 7 files changed, 9 insertions(+), 24 deletions(-) diff --git a/lib/providers/equipment_profile_provider.dart b/lib/providers/equipment_profile_provider.dart index 37b89df..91cc084 100644 --- a/lib/providers/equipment_profile_provider.dart +++ b/lib/providers/equipment_profile_provider.dart @@ -63,12 +63,18 @@ class EquipmentProfileProviderState extends State { final indexToUpdate = _profiles.indexWhere((element) => element.id == data.id); if (indexToUpdate >= 0) { _profiles[indexToUpdate] = data; + if (data.id == _selectedProfile.id) { + _selectedProfile = _profiles[indexToUpdate]; + } setState(() {}); } } void deleteProfile(EquipmentProfileData data) { _profiles.remove(data); + if (data.id == _selectedProfile.id) { + _selectedProfile = _profiles.first; + } setState(() {}); } } 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 d1775ea..e3d2ae7 100644 --- a/lib/screens/metering/components/camera_container/provider_container_camera.dart +++ b/lib/screens/metering/components/camera_container/provider_container_camera.dart @@ -10,7 +10,6 @@ import 'bloc_container_camera.dart'; import 'widget_container_camera.dart'; class CameraContainerProvider extends StatelessWidget { - final ValueChanged onEquipmentProfileChanged; final ExposurePair? fastest; final ExposurePair? slowest; final IsoValue iso; @@ -20,7 +19,6 @@ class CameraContainerProvider extends StatelessWidget { final List exposurePairs; const CameraContainerProvider({ - required this.onEquipmentProfileChanged, required this.fastest, required this.slowest, required this.iso, @@ -40,7 +38,6 @@ class CameraContainerProvider extends StatelessWidget { context.read(), ), child: CameraContainer( - onEquipmentProfileChanged: onEquipmentProfileChanged, fastest: fastest, slowest: slowest, isoValues: EquipmentProfile.of(context)?.isoValues ?? isoValues, 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 e398bb3..1acc1bb 100644 --- a/lib/screens/metering/components/camera_container/widget_container_camera.dart +++ b/lib/screens/metering/components/camera_container/widget_container_camera.dart @@ -19,7 +19,6 @@ import 'event_container_camera.dart'; import 'state_container_camera.dart'; class CameraContainer extends StatelessWidget { - final ValueChanged onEquipmentProfileChanged; final ExposurePair? fastest; final ExposurePair? slowest; final List isoValues; @@ -31,7 +30,6 @@ class CameraContainer extends StatelessWidget { final List exposurePairs; const CameraContainer({ - required this.onEquipmentProfileChanged, required this.fastest, required this.slowest, required this.isoValues, @@ -60,7 +58,6 @@ class CameraContainer extends StatelessWidget { children: [ MeteringTopBar( readingsContainer: ReadingsContainer( - onEquipmentProfileChanged: onEquipmentProfileChanged, fastest: fastest, slowest: slowest, isoValues: isoValues, 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 7c71de3..450791b 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 @@ -10,7 +10,6 @@ import 'bloc_container_light_sensor.dart'; import 'widget_container_light_sensor.dart'; class LightSensorContainerProvider extends StatelessWidget { - final ValueChanged onEquipmentProfileChanged; final ExposurePair? fastest; final ExposurePair? slowest; final IsoValue iso; @@ -20,7 +19,6 @@ class LightSensorContainerProvider extends StatelessWidget { final List exposurePairs; const LightSensorContainerProvider({ - required this.onEquipmentProfileChanged, required this.fastest, required this.slowest, required this.iso, @@ -40,7 +38,6 @@ class LightSensorContainerProvider extends StatelessWidget { context.read(), ), child: LightSensorContainer( - onEquipmentProfileChanged: onEquipmentProfileChanged, fastest: fastest, slowest: slowest, isoValues: EquipmentProfile.of(context)?.isoValues ?? isoValues, 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 60e067d..34018ac 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 @@ -7,7 +7,6 @@ import 'package:lightmeter/screens/metering/components/shared/readings_container import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; class LightSensorContainer extends StatelessWidget { - final ValueChanged onEquipmentProfileChanged; final ExposurePair? fastest; final ExposurePair? slowest; final List isoValues; @@ -19,7 +18,6 @@ class LightSensorContainer extends StatelessWidget { final List exposurePairs; const LightSensorContainer({ - required this.onEquipmentProfileChanged, required this.fastest, required this.slowest, required this.isoValues, @@ -38,7 +36,6 @@ class LightSensorContainer extends StatelessWidget { children: [ MeteringTopBar( readingsContainer: ReadingsContainer( - onEquipmentProfileChanged: onEquipmentProfileChanged, fastest: fastest, slowest: slowest, isoValues: isoValues, 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 ba38646..7aa51a9 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 @@ -10,7 +10,6 @@ import 'components/reading_value_container/widget_container_reading_value.dart'; /// Contains a column of fastest & slowest exposure pairs + a row of ISO and ND pickers class ReadingsContainer extends StatelessWidget { - final ValueChanged onEquipmentProfileChanged; final ExposurePair? fastest; final ExposurePair? slowest; final List isoValues; @@ -21,7 +20,6 @@ class ReadingsContainer extends StatelessWidget { final ValueChanged onNdChanged; const ReadingsContainer({ - required this.onEquipmentProfileChanged, required this.fastest, required this.slowest, required this.isoValues, @@ -43,10 +41,7 @@ class ReadingsContainer extends StatelessWidget { _EquipmentProfilePicker( selectedValue: EquipmentProfile.of(context)!, values: EquipmentProfiles.of(context)!, - onChanged: (value) { - EquipmentProfileProvider.of(context).setProfile(value); - onEquipmentProfileChanged(value); - }, + onChanged: EquipmentProfileProvider.of(context).setProfile, ), const _InnerPadding(), ], diff --git a/lib/screens/metering/screen_metering.dart b/lib/screens/metering/screen_metering.dart index e5e921b..c8aa3da 100644 --- a/lib/screens/metering/screen_metering.dart +++ b/lib/screens/metering/screen_metering.dart @@ -3,6 +3,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:lightmeter/data/models/ev_source_type.dart'; import 'package:lightmeter/data/models/exposure_pair.dart'; import 'package:lightmeter/environment.dart'; +import 'package:lightmeter/providers/equipment_profile_provider.dart'; import 'package:lightmeter/providers/ev_source_type_provider.dart'; import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; @@ -26,6 +27,7 @@ class _MeteringScreenState extends State { @override void didChangeDependencies() { super.didChangeDependencies(); + _bloc.add(EquipmentProfileChangedEvent(EquipmentProfile.of(context)!)); _bloc.add(StopTypeChangedEvent(context.watch())); } @@ -40,8 +42,6 @@ class _MeteringScreenState extends State { buildWhen: (_, current) => current is MeteringDataState, builder: (_, state) => state is MeteringDataState ? _MeteringContainerBuidler( - onEquipmentProfileChanged: (value) => - _bloc.add(EquipmentProfileChangedEvent(value)), fastest: state.fastest, slowest: state.slowest, iso: state.iso, @@ -71,7 +71,6 @@ class _MeteringScreenState extends State { } class _MeteringContainerBuidler extends StatelessWidget { - final ValueChanged onEquipmentProfileChanged; final ExposurePair? fastest; final ExposurePair? slowest; final IsoValue iso; @@ -81,7 +80,6 @@ class _MeteringContainerBuidler extends StatelessWidget { final List exposurePairs; const _MeteringContainerBuidler({ - required this.onEquipmentProfileChanged, required this.fastest, required this.slowest, required this.iso, @@ -95,7 +93,6 @@ class _MeteringContainerBuidler extends StatelessWidget { Widget build(BuildContext context) { return context.watch() == EvSourceType.camera ? CameraContainerProvider( - onEquipmentProfileChanged: onEquipmentProfileChanged, fastest: fastest, slowest: slowest, iso: iso, @@ -105,7 +102,6 @@ class _MeteringContainerBuidler extends StatelessWidget { exposurePairs: exposurePairs, ) : LightSensorContainerProvider( - onEquipmentProfileChanged: onEquipmentProfileChanged, fastest: fastest, slowest: slowest, iso: iso,