2023-11-01 06:43:15 +00:00
|
|
|
import "package:flutter/material.dart";
|
2023-11-01 09:46:38 +00:00
|
|
|
import "package:photos/core/constants.dart";
|
2023-11-01 06:43:15 +00:00
|
|
|
|
|
|
|
class RecentSearches with ChangeNotifier {
|
|
|
|
static RecentSearches? _instance;
|
|
|
|
|
|
|
|
RecentSearches._();
|
|
|
|
|
|
|
|
factory RecentSearches() => _instance ??= RecentSearches._();
|
|
|
|
|
2023-11-01 11:18:03 +00:00
|
|
|
final searches = <String>{};
|
2023-11-01 06:43:15 +00:00
|
|
|
|
2023-11-01 11:18:03 +00:00
|
|
|
void add(String query) {
|
|
|
|
searches.add(query);
|
2023-11-01 09:46:38 +00:00
|
|
|
while (searches.length > searchSectionLimit) {
|
|
|
|
searches.remove(searches.first);
|
|
|
|
}
|
2023-11-01 09:21:33 +00:00
|
|
|
//buffer for not surfacing a new recent search before going to the next
|
|
|
|
//screen
|
|
|
|
Future.delayed(const Duration(seconds: 1), () {
|
|
|
|
notifyListeners();
|
|
|
|
});
|
2023-11-01 06:43:15 +00:00
|
|
|
}
|
|
|
|
}
|