Subtitle for "custom range" in quick date picker

This commit is contained in:
exelix11 2025-10-13 22:16:43 +00:00 committed by Brandon Wees
parent eae28d5b0c
commit f08c4ae258
2 changed files with 63 additions and 50 deletions

View file

@ -1519,8 +1519,8 @@
"photos_count": "{count, plural, one {{count, number} Photo} other {{count, number} Photos}}", "photos_count": "{count, plural, one {{count, number} Photo} other {{count, number} Photos}}",
"photos_from_previous_years": "Photos from previous years", "photos_from_previous_years": "Photos from previous years",
"pick_a_location": "Pick a location", "pick_a_location": "Pick a location",
"pick_custom_range": "Custom range",
"pick_date_range": "Select a date range", "pick_date_range": "Select a date range",
"pick_exact_date": "Enter a custom interval",
"pin_code_changed_successfully": "Successfully changed PIN code", "pin_code_changed_successfully": "Successfully changed PIN code",
"pin_code_reset_successfully": "Successfully reset PIN code", "pin_code_reset_successfully": "Successfully reset PIN code",
"pin_code_setup_successfully": "Successfully setup a PIN code", "pin_code_setup_successfully": "Successfully setup a PIN code",

View file

@ -85,17 +85,14 @@ class CustomDateFilter extends DateFilterInputModel {
enum _QuickPickerType { last1Month, last3Months, last9Months, year, custom } enum _QuickPickerType { last1Month, last3Months, last9Months, year, custom }
class QuickDatePicker extends HookWidget { class QuickDatePicker extends HookWidget {
QuickDatePicker({ QuickDatePicker({super.key, required this.currentInput, required this.onSelect, required this.onRequestPicker})
super.key, : _selection = _selectionFromModel(currentInput),
required DateFilterInputModel? currentInput, _initialYear = _initialYearFromModel(currentInput);
required this.onSelect,
required this.onRequestPicker,
}) : _selection = _selectionFromModel(currentInput),
_initialYear = _initialYearFromModel(currentInput);
final Function() onRequestPicker; final Function() onRequestPicker;
final Function(DateFilterInputModel range) onSelect; final Function(DateFilterInputModel range) onSelect;
final DateFilterInputModel? currentInput;
final _QuickPickerType? _selection; final _QuickPickerType? _selection;
final int _initialYear; final int _initialYear;
@ -155,53 +152,69 @@ class QuickDatePicker extends HookWidget {
// We want the exact date picker to always be selectable. // We want the exact date picker to always be selectable.
// Even if it's already toggled it should always open the full date picker, RadioListTiles don't do that by default // Even if it's already toggled it should always open the full date picker, RadioListTiles don't do that by default
// so we wrap it in a InkWell // so we wrap it in a InkWell
Widget _exactPicker(BuildContext context) => InkWell( Widget _exactPicker(BuildContext context) {
onTap: onRequestPicker, final hasPreviousInput = currentInput != null && currentInput is CustomDateFilter;
child: IgnorePointer(
ignoring: true, return InkWell(
child: RadioListTile(title: const Text('pick_exact_date').tr(), value: _QuickPickerType.custom, toggleable: true), onTap: onRequestPicker,
), child: IgnorePointer(
); ignoring: true,
child: RadioListTile(
title: const Text('pick_custom_range').tr(),
subtitle: hasPreviousInput ? Text(currentInput!.asHumanReadable(context)) : null,
secondary: hasPreviousInput ? const Icon(Icons.edit) : null,
value: _QuickPickerType.custom,
toggleable: true,
),
),
);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Padding( return Padding(
padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom), padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
child: SingleChildScrollView( child: Scrollbar(
clipBehavior: Clip.none, // Depending on the screen size the last option might get cut off
child: RadioGroup( // Add a clear visual cue that there are more options when scrolling
onChanged: (value) { // When the screen size is large enough the scrollbar is hidden automatically
switch (value) { trackVisibility: true,
case _QuickPickerType.custom: thumbVisibility: true,
onRequestPicker(); child: SingleChildScrollView(
break; child: RadioGroup(
case _QuickPickerType.last1Month: onChanged: (value) {
onSelect(RecentMonthRangeFilter(1)); switch (value) {
break; case _QuickPickerType.custom:
case _QuickPickerType.last3Months: onRequestPicker();
onSelect(RecentMonthRangeFilter(3)); break;
break; case _QuickPickerType.last1Month:
case _QuickPickerType.last9Months: onSelect(RecentMonthRangeFilter(1));
onSelect(RecentMonthRangeFilter(9)); break;
break; case _QuickPickerType.last3Months:
case _QuickPickerType.year: onSelect(RecentMonthRangeFilter(3));
// The combobox triggers the onSelect event on its own so if this is ever selected it can only be on break;
// the default value set by the constructor case _QuickPickerType.last9Months:
onSelect(YearFilter(_initialYear)); onSelect(RecentMonthRangeFilter(9));
break; break;
default: case _QuickPickerType.year:
break; // The combobox triggers the onSelect event on its own so if this is ever selected it can only be on
} // the default value set by the constructor
}, onSelect(YearFilter(_initialYear));
groupValue: _selection, break;
child: Column( default:
children: [ break;
RadioListTile(title: _monthLabel(context, 1), value: _QuickPickerType.last1Month, toggleable: true), }
RadioListTile(title: _monthLabel(context, 3), value: _QuickPickerType.last3Months, toggleable: true), },
RadioListTile(title: _monthLabel(context, 9), value: _QuickPickerType.last9Months, toggleable: true), groupValue: _selection,
RadioListTile(title: _yearPicker(context), value: _QuickPickerType.year, toggleable: true), child: Column(
_exactPicker(context), children: [
], RadioListTile(title: _monthLabel(context, 1), value: _QuickPickerType.last1Month, toggleable: true),
RadioListTile(title: _monthLabel(context, 3), value: _QuickPickerType.last3Months, toggleable: true),
RadioListTile(title: _monthLabel(context, 9), value: _QuickPickerType.last9Months, toggleable: true),
RadioListTile(title: _yearPicker(context), value: _QuickPickerType.year, toggleable: true),
_exactPicker(context),
],
),
), ),
), ),
), ),