mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-22 07:20:39 +00:00
implemented DialogRangePicker
This commit is contained in:
parent
6f5eeed2e6
commit
7726bd8660
3 changed files with 115 additions and 34 deletions
|
@ -10,7 +10,6 @@ class DialogFilter<T extends PhotographyValue> extends StatefulWidget {
|
|||
final List<T> values;
|
||||
final List<T> selectedValues;
|
||||
final String Function(BuildContext context, T value) titleAdapter;
|
||||
final bool rangeSelect;
|
||||
|
||||
const DialogFilter({
|
||||
required this.icon,
|
||||
|
@ -19,7 +18,6 @@ class DialogFilter<T extends PhotographyValue> extends StatefulWidget {
|
|||
required this.values,
|
||||
required this.selectedValues,
|
||||
required this.titleAdapter,
|
||||
this.rangeSelect = false,
|
||||
super.key,
|
||||
});
|
||||
|
||||
|
@ -68,28 +66,7 @@ class _DialogFilterState<T extends PhotographyValue> extends State<DialogFilter<
|
|||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
setState(() {
|
||||
if (widget.rangeSelect) {
|
||||
if (value) {
|
||||
final indexOfChecked = checkboxValues.indexOf(value);
|
||||
if (indexOfChecked == -1) {
|
||||
checkboxValues[index] = value;
|
||||
} else if (indexOfChecked < index) {
|
||||
checkboxValues.fillRange(indexOfChecked, index + 1, value);
|
||||
} else {
|
||||
checkboxValues.fillRange(index, indexOfChecked, value);
|
||||
}
|
||||
} else {
|
||||
if (index > 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;
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
|
@ -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<T extends PhotographyValue> extends StatefulWidget {
|
||||
final Icon icon;
|
||||
final String title;
|
||||
final String description;
|
||||
final List<T> values;
|
||||
final List<T> 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<DialogRangePicker<T>> createState() => _DialogRangePickerState<T>();
|
||||
}
|
||||
|
||||
class _DialogRangePickerState<T extends PhotographyValue> extends State<DialogRangePicker<T>> {
|
||||
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),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
|
@ -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<ApertureValue> selectedApertureValues;
|
||||
|
@ -114,14 +115,22 @@ class _EquipmentListTile<T extends PhotographyValue> extends StatelessWidget {
|
|||
onTap: () {
|
||||
showDialog<List<T>>(
|
||||
context: context,
|
||||
builder: (_) => DialogFilter<T>(
|
||||
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(),
|
||||
rangeSelect: rangeSelect,
|
||||
),
|
||||
).then((values) {
|
||||
if (values != null) {
|
||||
|
|
Loading…
Reference in a new issue