File tree Expand file tree Collapse file tree 1 file changed +28
-1
lines changed Expand file tree Collapse file tree 1 file changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,33 @@ class SearchClient {
1717 : _http = httpClient,
1818 _controller = controller;
1919
20+ /// Fetches for suggestions based on the given query.
21+ ///
22+ /// [query] The query to search for suggestions for.
23+ Future <List <String >> fetchSuggestion (
24+ String query,
25+ ) async {
26+ if (query.isEmpty) {
27+ return [];
28+ }
29+
30+ final clientId = await _controller.getClientId ();
31+
32+ final uri = Uri .https (
33+ 'api-v2.soundcloud.com' ,
34+ '/search/queries' , {
35+ 'q' : query,
36+ 'client_id' : clientId,
37+ }
38+ );
39+
40+ final response = await _http.get (uri);
41+ final json = jsonDecode (response.body);
42+ final collection = json['collection' ] as List ;
43+
44+ return collection.map ((suggestion) => suggestion['query' ] as String ).toList ();
45+ }
46+
2047 /// Searches for the provided [query] with the specified [searchFilter] .
2148 ///
2249 /// Search results are offset by the specified [offset] , with each batch containing
@@ -178,4 +205,4 @@ class SearchClient {
178205 offset: offset,
179206 limit: limit
180207 ).map ((b) => b.cast <UserSearchResult >());
181- }
208+ }
You can’t perform that action at this time.
0 commit comments