find method
Future<List<Snap> >
find({
- String? query,
- String? name,
- String? category,
- @Deprecated('Replaced with category') String? section,
- SnapFindFilter? filter,
- SnapFindScope? scope,
Searches for snaps in the store.
If query
is provided, searches for snaps that match the given string.
If name
is provided, match the snap with the given name.
If category
is provided, search within that store category.
If filter
is provided, alter the collection searched:
- 'refresh': search refreshable snaps. Can't be used with
query
norname
. - 'private': search private snaps. Can't be used with
query
. Ifscope
is provided, adjust the search scope. - 'wide': search for snaps that don't have a stable release.
Implementation
Future<List<Snap>> find(
{String? query,
String? name,
String? category,
@Deprecated('Replaced with category') String? section,
SnapFindFilter? filter,
SnapFindScope? scope}) async {
var queryParameters = <String, String>{};
if (query != null) {
queryParameters['q'] = query;
}
if (name != null) {
queryParameters['name'] = name;
}
if (category != null) {
queryParameters['category'] = category;
}
if (section != null) {
queryParameters['section'] = section;
}
if (filter != null) {
var value = {
SnapFindFilter.private: 'private',
SnapFindFilter.refresh: 'refresh'
}[filter];
if (value != null) {
queryParameters['select'] = value;
}
}
if (scope != null) {
var value = {SnapFindScope.wide: 'wide'}[scope];
if (value != null) {
queryParameters['scope'] = value;
}
}
var result = await _getSync('/v2/find', queryParameters);
var snaps = <Snap>[];
for (var snap in result) {
snaps.add(Snap.fromJson(snap));
}
return snaps;
}