update carton form and add recent search
This commit is contained in:
@@ -88,4 +88,24 @@ class SharedPref {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
prefs.remove(key);
|
||||
}
|
||||
|
||||
static Future<void> saveRecentSearch(String key, String query) async {
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
//Use `Set` to avoid duplication of recentSearches
|
||||
Set<String> allSearches = prefs.getStringList(key)?.toSet() ?? {};
|
||||
|
||||
//Place it at first in the set
|
||||
allSearches = {query, ...allSearches};
|
||||
prefs.setStringList(key, allSearches.toList());
|
||||
}
|
||||
|
||||
static Future<List<String>?> getRecentSearch(String key, String query) async {
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
final allSearches = prefs.getStringList(key);
|
||||
return allSearches!.where((search) => search.startsWith(query)).toList();
|
||||
}
|
||||
|
||||
static Future<void> clearRecentSearch(String key) async {
|
||||
return await _remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user