set zoom on equipment profile change

This commit is contained in:
Vadim 2024-04-06 22:58:13 +02:00
parent fe98bf163f
commit 153cb9ca51
4 changed files with 25 additions and 8 deletions

View file

@ -1,7 +1,9 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:lightmeter/providers/equipment_profile_provider.dart';
import 'package:lightmeter/screens/shared/ruler_slider/widget_slider_ruler.dart'; import 'package:lightmeter/screens/shared/ruler_slider/widget_slider_ruler.dart';
import 'package:lightmeter/utils/double_to_zoom.dart';
class ZoomSlider extends StatelessWidget { class ZoomSlider extends StatefulWidget {
final RangeValues range; final RangeValues range;
final double value; final double value;
final ValueChanged<double> onChanged; final ValueChanged<double> onChanged;
@ -13,16 +15,27 @@ class ZoomSlider extends StatelessWidget {
super.key, super.key,
}); });
@override
State<ZoomSlider> createState() => _ZoomSliderState();
}
class _ZoomSliderState extends State<ZoomSlider> {
@override
void didChangeDependencies() {
super.didChangeDependencies();
widget.onChanged(EquipmentProfiles.selectedOf(context).lensZoom);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return RulerSlider( return RulerSlider(
range: range, range: widget.range,
value: value, value: widget.value,
onChanged: onChanged, onChanged: widget.onChanged,
icon: Icons.search, icon: Icons.search,
defaultValue: range.start, defaultValue: EquipmentProfiles.selectedOf(context).lensZoom,
rulerValueAdapter: (value) => value.toStringAsFixed(0), rulerValueAdapter: (value) => value.toStringAsFixed(0),
valueAdapter: (value) => 'x${value.toStringAsFixed(2)}', valueAdapter: (value) => value.toZoom(),
); );
} }
} }

View file

@ -26,7 +26,7 @@ class SliderPickerListTile extends StatelessWidget {
return ListTile( return ListTile(
leading: Icon(icon), leading: Icon(icon),
title: Text(title), title: Text(title),
trailing: Text(value.toString()), trailing: Text(valueAdapter(context, value)),
onTap: () { onTap: () {
showDialog<double>( showDialog<double>(
context: context, context: context,

View file

@ -8,6 +8,7 @@ import 'package:lightmeter/screens/settings/components/metering/components/equip
import 'package:lightmeter/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_container/components/range_picker_list_tile/widget_list_tile_range_picker.dart'; import 'package:lightmeter/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_container/components/range_picker_list_tile/widget_list_tile_range_picker.dart';
import 'package:lightmeter/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_container/components/slider_picker_list_tile/widget_list_tile_slider_picker.dart'; import 'package:lightmeter/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_container/components/slider_picker_list_tile/widget_list_tile_slider_picker.dart';
import 'package:lightmeter/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_name_dialog/widget_dialog_equipment_profile_name.dart'; import 'package:lightmeter/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_name_dialog/widget_dialog_equipment_profile_name.dart';
import 'package:lightmeter/utils/double_to_zoom.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
class EquipmentProfileContainer extends StatefulWidget { class EquipmentProfileContainer extends StatefulWidget {
@ -276,7 +277,7 @@ class _AnimatedEquipmentListTiles extends AnimatedWidget {
value: equipmentData.lensZoom, value: equipmentData.lensZoom,
range: const RangeValues(1, 7), range: const RangeValues(1, 7),
onChanged: onLensZoomChanged, onChanged: onLensZoomChanged,
valueAdapter: (context, value) => 'x${value.toStringAsFixed(2)}', valueAdapter: (_, value) => value.toZoom(),
), ),
ListTile( ListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: Dimens.paddingM), contentPadding: const EdgeInsets.symmetric(horizontal: Dimens.paddingM),

View file

@ -0,0 +1,3 @@
extension DoubleToZoom on double {
String toZoom() => 'x${toStringAsFixed(2)}';
}