mirror of
https://github.com/immich-app/immich
synced 2025-11-07 17:27:20 +00:00
Move quick_date_picker.dart to lib/presentation/widgets/search
This commit is contained in:
parent
a1174683a4
commit
78467c078e
2 changed files with 1 additions and 1 deletions
|
|
@ -0,0 +1,70 @@
|
|||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:immich_mobile/extensions/translate_extensions.dart';
|
||||
|
||||
class QuickDatePicker extends HookWidget {
|
||||
const QuickDatePicker({super.key, required this.onSelect, required this.onRequestPicker});
|
||||
|
||||
final Function() onRequestPicker;
|
||||
final Function(DateTimeRange<DateTime> range) onSelect;
|
||||
|
||||
void _selectRange(DateTimeRange range) {
|
||||
// Ensure we don't go beyond today, eg when picking "in $current_year"
|
||||
final now = DateTime.now();
|
||||
if (range.end.isAfter(now)) {
|
||||
range = DateTimeRange(start: range.start, end: now);
|
||||
}
|
||||
|
||||
onSelect(range);
|
||||
}
|
||||
|
||||
ListTile _monthListTile(BuildContext context, int monthsFromNow) {
|
||||
String label = 'last_months'.t(context: context, args: {"count": monthsFromNow.toString()});
|
||||
return ListTile(
|
||||
title: Text(label),
|
||||
onTap: () {
|
||||
final now = DateTime.now();
|
||||
// We use the first of the target month here to avoid issues with different month lengths
|
||||
// the negative overflow of months is handled by DateTime correctly
|
||||
final from = DateTime(now.year, now.month - monthsFromNow, 1);
|
||||
_selectRange(DateTimeRange(start: from, end: now));
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListView.builder(
|
||||
itemBuilder: (context, index) {
|
||||
if (index == 0) {
|
||||
return ListTile(
|
||||
title: Text('pick_exact_date'.tr()),
|
||||
onTap: () {
|
||||
onRequestPicker();
|
||||
},
|
||||
);
|
||||
} else if (index == 1) {
|
||||
return _monthListTile(context, 1);
|
||||
} else if (index == 2) {
|
||||
return _monthListTile(context, 3);
|
||||
} else if (index == 3) {
|
||||
return _monthListTile(context, 9);
|
||||
} else {
|
||||
final now = DateTime.now();
|
||||
final years = index - 4;
|
||||
final year = now.year - years;
|
||||
return ListTile(
|
||||
title: Text("in_year".tr(namedArgs: {"year": year.toString()})),
|
||||
onTap: () {
|
||||
final from = DateTime(year, 1, 1);
|
||||
final to = DateTime(year, 12, 31, 23, 59, 59);
|
||||
_selectRange(DateTimeRange(start: from, end: to));
|
||||
},
|
||||
);
|
||||
}
|
||||
},
|
||||
itemCount: 50,
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue