From 7726bd8660b3e30fa5b60d5e86f5eea73f385a35 Mon Sep 17 00:00:00 2001 From: Vadim Date: Wed, 29 Mar 2023 17:11:51 +0300 Subject: [PATCH] implemented `DialogRangePicker` --- .../dialog_filter/widget_dialog_filter.dart | 25 +---- .../widget_dialog_picker_range.dart | 95 +++++++++++++++++++ .../widget_list_tiles_equipments.dart | 29 ++++-- 3 files changed, 115 insertions(+), 34 deletions(-) rename lib/screens/settings/components/{shared => metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_container/components/equipment_list_tiles/components}/dialog_filter/widget_dialog_filter.dart (75%) create mode 100644 lib/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_container/components/equipment_list_tiles/components/dialog_range_picker/widget_dialog_picker_range.dart diff --git a/lib/screens/settings/components/shared/dialog_filter/widget_dialog_filter.dart b/lib/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_container/components/equipment_list_tiles/components/dialog_filter/widget_dialog_filter.dart similarity index 75% rename from lib/screens/settings/components/shared/dialog_filter/widget_dialog_filter.dart rename to lib/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_container/components/equipment_list_tiles/components/dialog_filter/widget_dialog_filter.dart index ff828a8..48b81d2 100644 --- a/lib/screens/settings/components/shared/dialog_filter/widget_dialog_filter.dart +++ b/lib/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_container/components/equipment_list_tiles/components/dialog_filter/widget_dialog_filter.dart @@ -10,7 +10,6 @@ class DialogFilter extends StatefulWidget { final List values; final List selectedValues; final String Function(BuildContext context, T value) titleAdapter; - final bool rangeSelect; const DialogFilter({ required this.icon, @@ -19,7 +18,6 @@ class DialogFilter extends StatefulWidget { required this.values, required this.selectedValues, required this.titleAdapter, - this.rangeSelect = false, super.key, }); @@ -68,28 +66,7 @@ class _DialogFilterState extends State checkboxValues.length / 2) { - checkboxValues.fillRange(index, checkboxValues.length, false); - checkboxValues[index] = value; - } else { - checkboxValues.fillRange(0, index, false); - checkboxValues[index] = value; - } - } - } else { - checkboxValues[index] = value; - } + checkboxValues[index] = value; }); } }, diff --git a/lib/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_container/components/equipment_list_tiles/components/dialog_range_picker/widget_dialog_picker_range.dart b/lib/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_container/components/equipment_list_tiles/components/dialog_range_picker/widget_dialog_picker_range.dart new file mode 100644 index 0000000..a1c8bc1 --- /dev/null +++ b/lib/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_container/components/equipment_list_tiles/components/dialog_range_picker/widget_dialog_picker_range.dart @@ -0,0 +1,95 @@ +import 'package:flutter/material.dart'; +import 'package:lightmeter/generated/l10n.dart'; +import 'package:lightmeter/res/dimens.dart'; +import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; + +class DialogRangePicker extends StatefulWidget { + final Icon icon; + final String title; + final String description; + final List values; + final List selectedValues; + final String Function(BuildContext context, T value) titleAdapter; + + const DialogRangePicker({ + required this.icon, + required this.title, + required this.description, + required this.values, + required this.selectedValues, + required this.titleAdapter, + super.key, + }); + + @override + State> createState() => _DialogRangePickerState(); +} + +class _DialogRangePickerState extends State> { + late int _start = widget.values.indexWhere((e) => e.value == widget.selectedValues.first.value); + late int _end = widget.values.indexWhere((e) => e.value == widget.selectedValues.last.value); + + @override + Widget build(BuildContext context) { + return AlertDialog( + icon: widget.icon, + titlePadding: Dimens.dialogIconTitlePadding, + title: Text(widget.title), + contentPadding: EdgeInsets.zero, + content: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Padding( + padding: Dimens.dialogIconTitlePadding, + child: Text(widget.description), + ), + Padding( + padding: const EdgeInsets.symmetric(horizontal: Dimens.paddingL), + child: DefaultTextStyle( + style: Theme.of(context).textTheme.bodyLarge!, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text(widget.values[_start].toString()), + Text(widget.values[_end].toString()), + ], + ), + ), + ), + Row( + children: [ + Expanded( + child: RangeSlider( + values: RangeValues( + _start.toDouble(), + _end.toDouble(), + ), + min: 0, + max: widget.values.length.toDouble() - 1, + divisions: widget.values.length - 1, + onChanged: (value) { + setState(() { + _start = value.start.toInt(); + _end = value.end.toInt(); + }); + }, + ), + ), + ], + ), + ], + ), + actionsPadding: Dimens.dialogActionsPadding, + actions: [ + TextButton( + onPressed: Navigator.of(context).pop, + child: Text(S.of(context).cancel), + ), + TextButton( + onPressed: () => Navigator.of(context).pop(widget.values.sublist(_start, _end + 1)), + child: Text(S.of(context).save), + ), + ], + ); + } +} diff --git a/lib/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_container/components/equipment_list_tiles/widget_list_tiles_equipments.dart b/lib/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_container/components/equipment_list_tiles/widget_list_tiles_equipments.dart index 553a318..411530c 100644 --- a/lib/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_container/components/equipment_list_tiles/widget_list_tiles_equipments.dart +++ b/lib/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_container/components/equipment_list_tiles/widget_list_tiles_equipments.dart @@ -1,7 +1,8 @@ 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/equipment_list_tiles/components/dialog_range_picker/widget_dialog_picker_range.dart'; import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; -import 'package:lightmeter/screens/settings/components/shared/dialog_filter/widget_dialog_filter.dart'; +import 'package:lightmeter/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_container/components/equipment_list_tiles/components/dialog_filter/widget_dialog_filter.dart'; class EquipmentListTiles extends StatelessWidget { final List selectedApertureValues; @@ -114,15 +115,23 @@ class _EquipmentListTile extends StatelessWidget { onTap: () { showDialog>( context: context, - builder: (_) => DialogFilter( - icon: Icon(icon), - title: title, - description: description, - values: values, - selectedValues: selectedValues, - titleAdapter: (_, value) => value.toString(), - rangeSelect: rangeSelect, - ), + builder: (_) => rangeSelect + ? DialogRangePicker( + icon: Icon(icon), + title: title, + description: description, + values: values, + selectedValues: selectedValues, + titleAdapter: (_, value) => value.toString(), + ) + : DialogFilter( + icon: Icon(icon), + title: title, + description: description, + values: values, + selectedValues: selectedValues, + titleAdapter: (_, value) => value.toString(), + ), ).then((values) { if (values != null) { onChanged(values);