2023-03-30 19:24:18 +00:00
|
|
|
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;
|
2024-04-30 10:44:01 +00:00
|
|
|
final String Function(BuildContext context, T value) valueAdapter;
|
2023-03-30 19:24:18 +00:00
|
|
|
|
|
|
|
const DialogRangePicker({
|
|
|
|
required this.icon,
|
|
|
|
required this.title,
|
|
|
|
required this.description,
|
|
|
|
required this.values,
|
|
|
|
required this.selectedValues,
|
2024-04-30 10:44:01 +00:00
|
|
|
required this.valueAdapter,
|
2023-03-30 19:24:18 +00:00
|
|
|
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,
|
2023-11-14 11:26:34 +00:00
|
|
|
content: SizedBox(
|
|
|
|
width: double.maxFinite,
|
|
|
|
child: 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: [
|
2024-04-30 10:44:01 +00:00
|
|
|
Text(widget.valueAdapter(context, widget.values[_start])),
|
|
|
|
Text(widget.valueAdapter(context, widget.values[_end])),
|
2023-11-14 11:26:34 +00:00
|
|
|
],
|
|
|
|
),
|
2023-03-30 19:24:18 +00:00
|
|
|
),
|
|
|
|
),
|
2023-11-14 11:26:34 +00:00
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: RangeSlider(
|
|
|
|
values: RangeValues(
|
|
|
|
_start.toDouble(),
|
|
|
|
_end.toDouble(),
|
|
|
|
),
|
|
|
|
max: widget.values.length.toDouble() - 1,
|
|
|
|
divisions: widget.values.length - 1,
|
|
|
|
onChanged: (value) {
|
|
|
|
setState(() {
|
|
|
|
_start = value.start.round();
|
|
|
|
_end = value.end.round();
|
|
|
|
});
|
|
|
|
},
|
2023-03-30 19:24:18 +00:00
|
|
|
),
|
|
|
|
),
|
2023-11-14 11:26:34 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2023-03-30 19:24:18 +00:00
|
|
|
),
|
|
|
|
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),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|