cache years and its durations

This commit is contained in:
ashilkn 2022-08-22 09:44:38 +05:30
parent 1efcd0fa27
commit 6e30282051
2 changed files with 28 additions and 5 deletions

23
lib/data/years.dart Normal file
View file

@ -0,0 +1,23 @@
import 'package:photos/utils/date_time_util.dart';
class YearsData {
final List<YearData> yearsData = [];
YearsData._privateConstructor() {
for (int year = 1970; year <= currentYear; year++) {
yearsData.add(
YearData(year.toString(), year, [
DateTime(year).microsecondsSinceEpoch,
DateTime(year + 1).microsecondsSinceEpoch,
]),
);
}
}
static final YearsData instance = YearsData._privateConstructor();
}
class YearData {
final String yearInString;
final int yearInInt;
final List<int> duration;
YearData(this.yearInString, this.yearInInt, this.duration);
}

View file

@ -171,11 +171,11 @@ class _SearchWidgetState extends State<SearchWidget> {
Completer completer,
List<SearchResult> allResults,
) async {
final queryAsIntForYear = int.tryParse(query);
if (_isYearValid(queryAsIntForYear)) {
final queryAsInt = int.tryParse(query);
if (_isYearValid(queryAsInt)) {
final yearResult =
await _searchService.getYearSearchResults(queryAsIntForYear);
allResults.add(yearResult); //only one year will be returned
await _searchService.getYearSearchResults(queryAsInt, query);
allResults.add(yearResult);
}
final holidayResults = await _searchService.getHolidaySearchResults(query);
@ -196,6 +196,6 @@ class _SearchWidgetState extends State<SearchWidget> {
}
bool _isYearValid(int year) {
return year != null && year >= 1970 && year <= currentYear;
return year != null && year <= currentYear;
}
}