split EquipmentListTiles widget

This commit is contained in:
Vadim 2024-04-06 22:47:15 +02:00
parent 37219920a5
commit fe98bf163f
4 changed files with 154 additions and 160 deletions

View file

@ -1,146 +0,0 @@
import 'package:flutter/material.dart';
import 'package:lightmeter/generated/l10n.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/shared/dialog_filter/widget_dialog_filter.dart';
import 'package:lightmeter/screens/settings/components/shared/dialog_range_picker/widget_dialog_picker_range.dart';
import 'package:lightmeter/screens/settings/components/shared/dialog_slider_picker/widget_dialog_slider_picker.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
class EquipmentListTiles extends StatelessWidget {
final List<ApertureValue> selectedApertureValues;
final List<IsoValue> selectedIsoValues;
final List<NdValue> selectedNdValues;
final List<ShutterSpeedValue> selectedShutterSpeedValues;
final ValueChanged<List<ApertureValue>> onApertureValuesSelected;
final ValueChanged<List<IsoValue>> onIsoValuesSelecred;
final ValueChanged<List<NdValue>> onNdValuesSelected;
final ValueChanged<List<ShutterSpeedValue>> onShutterSpeedValuesSelected;
const EquipmentListTiles({
required this.selectedApertureValues,
required this.selectedIsoValues,
required this.selectedNdValues,
required this.selectedShutterSpeedValues,
required this.onApertureValuesSelected,
required this.onIsoValuesSelecred,
required this.onNdValuesSelected,
required this.onShutterSpeedValuesSelected,
super.key,
});
@override
Widget build(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
_EquipmentListTile<IsoValue>(
icon: Icons.iso,
title: S.of(context).isoValues,
description: S.of(context).isoValuesFilterDescription,
values: IsoValue.values,
selectedValues: selectedIsoValues,
rangeSelect: false,
onChanged: onIsoValuesSelecred,
),
_EquipmentListTile<NdValue>(
icon: Icons.filter_b_and_w,
title: S.of(context).ndFilters,
description: S.of(context).ndFiltersFilterDescription,
values: NdValue.values,
selectedValues: selectedNdValues,
rangeSelect: false,
onChanged: onNdValuesSelected,
),
_EquipmentListTile<ApertureValue>(
icon: Icons.camera,
title: S.of(context).apertureValues,
description: S.of(context).apertureValuesFilterDescription,
values: ApertureValue.values,
selectedValues: selectedApertureValues,
rangeSelect: true,
onChanged: onApertureValuesSelected,
),
_EquipmentListTile<ShutterSpeedValue>(
icon: Icons.shutter_speed,
title: S.of(context).shutterSpeedValues,
description: S.of(context).shutterSpeedValuesFilterDescription,
values: ShutterSpeedValue.values,
selectedValues: selectedShutterSpeedValues,
rangeSelect: true,
onChanged: onShutterSpeedValuesSelected,
),
SliderPickerListTile(
icon: Icons.zoom_in,
title: S.of(context).lensZoom,
description: S.of(context).lensZoomDescription,
value: 1.0,
range: const RangeValues(1, 7),
onChanged: (value) {},
valueAdapter: (context, value) => 'x${value.toStringAsFixed(2)}',
),
],
);
}
}
class _EquipmentListTile<T extends PhotographyValue> extends StatelessWidget {
final IconData icon;
final String title;
final String description;
final List<T> selectedValues;
final List<T> values;
final ValueChanged<List<T>> onChanged;
final bool rangeSelect;
const _EquipmentListTile({
required this.icon,
required this.title,
required this.description,
required this.selectedValues,
required this.values,
required this.onChanged,
required this.rangeSelect,
super.key,
});
@override
Widget build(BuildContext context) {
return ListTile(
leading: Icon(icon),
title: Text(title),
trailing: rangeSelect
? Text("${selectedValues.first} - ${selectedValues.last}")
: Text(
values.length == selectedValues.length
? S.of(context).equipmentProfileAllValues
: selectedValues.length.toString(),
),
onTap: () {
showDialog<List<T>>(
context: context,
builder: (_) => rangeSelect
? DialogRangePicker<T>(
icon: Icon(icon),
title: title,
description: description,
values: values,
selectedValues: selectedValues,
titleAdapter: (_, value) => value.toString(),
)
: DialogFilter<T>(
icon: Icon(icon),
title: title,
description: description,
values: values,
selectedValues: selectedValues,
titleAdapter: (_, value) => value.toString(),
),
).then((values) {
if (values != null) {
onChanged(values);
}
});
},
);
}
}

View file

@ -0,0 +1,53 @@
import 'package:flutter/material.dart';
import 'package:lightmeter/generated/l10n.dart';
import 'package:lightmeter/screens/settings/components/shared/dialog_filter/widget_dialog_filter.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
class FilterListTile<T extends PhotographyValue> extends StatelessWidget {
final IconData icon;
final String title;
final String description;
final List<T> selectedValues;
final List<T> values;
final ValueChanged<List<T>> onChanged;
const FilterListTile({
required this.icon,
required this.title,
required this.description,
required this.selectedValues,
required this.values,
required this.onChanged,
super.key,
});
@override
Widget build(BuildContext context) {
return ListTile(
leading: Icon(icon),
title: Text(title),
trailing: Text(
values.length == selectedValues.length
? S.of(context).equipmentProfileAllValues
: selectedValues.length.toString(),
),
onTap: () {
showDialog<List<T>>(
context: context,
builder: (_) => DialogFilter<T>(
icon: Icon(icon),
title: title,
description: description,
values: values,
selectedValues: selectedValues,
titleAdapter: (_, value) => value.toString(),
),
).then((values) {
if (values != null) {
onChanged(values);
}
});
},
);
}
}

View file

@ -0,0 +1,48 @@
import 'package:flutter/material.dart';
import 'package:lightmeter/screens/settings/components/shared/dialog_range_picker/widget_dialog_picker_range.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
class RangePickerListTile<T extends PhotographyValue> extends StatelessWidget {
final IconData icon;
final String title;
final String description;
final List<T> selectedValues;
final List<T> values;
final ValueChanged<List<T>> onChanged;
const RangePickerListTile({
required this.icon,
required this.title,
required this.description,
required this.selectedValues,
required this.values,
required this.onChanged,
super.key,
});
@override
Widget build(BuildContext context) {
return ListTile(
leading: Icon(icon),
title: Text(title),
trailing: Text("${selectedValues.first} - ${selectedValues.last}"),
onTap: () {
showDialog<List<T>>(
context: context,
builder: (_) => DialogRangePicker<T>(
icon: Icon(icon),
title: title,
description: description,
values: values,
selectedValues: selectedValues,
titleAdapter: (_, value) => value.toString(),
),
).then((values) {
if (values != null) {
onChanged(values);
}
});
},
);
}
}

View file

@ -4,7 +4,9 @@ import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart'; import 'package:flutter/scheduler.dart';
import 'package:lightmeter/generated/l10n.dart'; import 'package:lightmeter/generated/l10n.dart';
import 'package:lightmeter/res/dimens.dart'; import 'package:lightmeter/res/dimens.dart';
import 'package:lightmeter/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_container/components/equipment_list_tiles/widget_list_tiles_equipments.dart'; import 'package:lightmeter/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_container/components/filter_list_tile/widget_list_tile_filter.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_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:m3_lightmeter_resources/m3_lightmeter_resources.dart'; import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
@ -28,8 +30,7 @@ class EquipmentProfileContainer extends StatefulWidget {
State<EquipmentProfileContainer> createState() => EquipmentProfileContainerState(); State<EquipmentProfileContainer> createState() => EquipmentProfileContainerState();
} }
class EquipmentProfileContainerState extends State<EquipmentProfileContainer> class EquipmentProfileContainerState extends State<EquipmentProfileContainer> with TickerProviderStateMixin {
with TickerProviderStateMixin {
late EquipmentProfile _equipmentData = EquipmentProfile( late EquipmentProfile _equipmentData = EquipmentProfile(
id: widget.data.id, id: widget.data.id,
name: widget.data.name, name: widget.data.name,
@ -37,6 +38,7 @@ class EquipmentProfileContainerState extends State<EquipmentProfileContainer>
ndValues: widget.data.ndValues, ndValues: widget.data.ndValues,
shutterSpeedValues: widget.data.shutterSpeedValues, shutterSpeedValues: widget.data.shutterSpeedValues,
isoValues: widget.data.isoValues, isoValues: widget.data.isoValues,
lensZoom: widget.data.lensZoom,
); );
late final AnimationController _controller = AnimationController( late final AnimationController _controller = AnimationController(
@ -55,6 +57,7 @@ class EquipmentProfileContainerState extends State<EquipmentProfileContainer>
ndValues: widget.data.ndValues, ndValues: widget.data.ndValues,
shutterSpeedValues: widget.data.shutterSpeedValues, shutterSpeedValues: widget.data.shutterSpeedValues,
isoValues: widget.data.isoValues, isoValues: widget.data.isoValues,
lensZoom: widget.data.lensZoom,
); );
} }
@ -113,6 +116,10 @@ class EquipmentProfileContainerState extends State<EquipmentProfileContainer>
_equipmentData = _equipmentData.copyWith(shutterSpeedValues: value); _equipmentData = _equipmentData.copyWith(shutterSpeedValues: value);
widget.onUpdate(_equipmentData); widget.onUpdate(_equipmentData);
}, },
onLensZoomChanged: (value) {
_equipmentData = _equipmentData.copyWith(lensZoom: value);
widget.onUpdate(_equipmentData);
},
onCopy: widget.onCopy, onCopy: widget.onCopy,
onDelete: widget.onDelete, onDelete: widget.onDelete,
), ),
@ -154,8 +161,7 @@ class EquipmentProfileContainerState extends State<EquipmentProfileContainer>
} }
class _AnimatedNameLeading extends AnimatedWidget { class _AnimatedNameLeading extends AnimatedWidget {
const _AnimatedNameLeading({required AnimationController controller}) const _AnimatedNameLeading({required AnimationController controller}) : super(listenable: controller);
: super(listenable: controller);
Animation<double> get _progress => listenable as Animation<double>; Animation<double> get _progress => listenable as Animation<double>;
@ -200,6 +206,7 @@ class _AnimatedEquipmentListTiles extends AnimatedWidget {
final ValueChanged<List<IsoValue>> onIsoValuesSelecred; final ValueChanged<List<IsoValue>> onIsoValuesSelecred;
final ValueChanged<List<NdValue>> onNdValuesSelected; final ValueChanged<List<NdValue>> onNdValuesSelected;
final ValueChanged<List<ShutterSpeedValue>> onShutterSpeedValuesSelected; final ValueChanged<List<ShutterSpeedValue>> onShutterSpeedValuesSelected;
final ValueChanged<double> onLensZoomChanged;
final VoidCallback onCopy; final VoidCallback onCopy;
final VoidCallback onDelete; final VoidCallback onDelete;
@ -210,6 +217,7 @@ class _AnimatedEquipmentListTiles extends AnimatedWidget {
required this.onIsoValuesSelecred, required this.onIsoValuesSelecred,
required this.onNdValuesSelected, required this.onNdValuesSelected,
required this.onShutterSpeedValuesSelected, required this.onShutterSpeedValuesSelected,
required this.onLensZoomChanged,
required this.onCopy, required this.onCopy,
required this.onDelete, required this.onDelete,
}) : super(listenable: controller); }) : super(listenable: controller);
@ -229,15 +237,46 @@ class _AnimatedEquipmentListTiles extends AnimatedWidget {
opacity: _progress.value, opacity: _progress.value,
child: Column( child: Column(
children: [ children: [
EquipmentListTiles( FilterListTile<IsoValue>(
selectedApertureValues: equipmentData.apertureValues, icon: Icons.iso,
selectedIsoValues: equipmentData.isoValues, title: S.of(context).isoValues,
selectedNdValues: equipmentData.ndValues, description: S.of(context).isoValuesFilterDescription,
selectedShutterSpeedValues: equipmentData.shutterSpeedValues, values: IsoValue.values,
onApertureValuesSelected: onApertureValuesSelected, selectedValues: equipmentData.isoValues,
onIsoValuesSelecred: onIsoValuesSelecred, onChanged: onIsoValuesSelecred,
onNdValuesSelected: onNdValuesSelected, ),
onShutterSpeedValuesSelected: onShutterSpeedValuesSelected, FilterListTile<NdValue>(
icon: Icons.filter_b_and_w,
title: S.of(context).ndFilters,
description: S.of(context).ndFiltersFilterDescription,
values: NdValue.values,
selectedValues: equipmentData.ndValues,
onChanged: onNdValuesSelected,
),
RangePickerListTile<ApertureValue>(
icon: Icons.camera,
title: S.of(context).apertureValues,
description: S.of(context).apertureValuesFilterDescription,
values: ApertureValue.values,
selectedValues: equipmentData.apertureValues,
onChanged: onApertureValuesSelected,
),
RangePickerListTile<ShutterSpeedValue>(
icon: Icons.shutter_speed,
title: S.of(context).shutterSpeedValues,
description: S.of(context).shutterSpeedValuesFilterDescription,
values: ShutterSpeedValue.values,
selectedValues: equipmentData.shutterSpeedValues,
onChanged: onShutterSpeedValuesSelected,
),
SliderPickerListTile(
icon: Icons.zoom_in,
title: S.of(context).lensZoom,
description: S.of(context).lensZoomDescription,
value: equipmentData.lensZoom,
range: const RangeValues(1, 7),
onChanged: onLensZoomChanged,
valueAdapter: (context, value) => 'x${value.toStringAsFixed(2)}',
), ),
ListTile( ListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: Dimens.paddingM), contentPadding: const EdgeInsets.symmetric(horizontal: Dimens.paddingM),