You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Most functions return a stream of results in the
22
-
// form of Stream<Iterable<E>>.
21
+
// Most functions return a stream of results in the form of Stream<Iterable<E>>.
23
22
// The number of results returned in each Iterable<E>, as well as
24
-
// the search result offset and search filter are optional parameters.
23
+
// the result offset and search filter are optional parameters.
25
24
final stream = client.search(
26
25
'Haddaway - What Is Love',
27
26
searchFilter: SearchFilter.tracks,
@@ -32,11 +31,23 @@ final streamIterator = StreamIterator(stream);
32
31
33
32
while (await streamIterator.moveNext()) {
34
33
for (final result in streamIterator.current) {
35
-
print(result.title);
34
+
// Use pattern matching for mixed streams
35
+
switch (result) {
36
+
case final UserSearchResult user:
37
+
break;
38
+
39
+
case final TrackSearchResult track:
40
+
break;
41
+
42
+
case final PlaylistSearchResult playlist:
43
+
break;
44
+
}
36
45
}
37
46
}
38
47
```
39
48
49
+
Alternatively, use one of the specialised functions, such as `getUsers(...)`, `getTracks(...)`, etc., which casts each item in the returned `Iterable<E>` to the specified type.
50
+
40
51
### Querying users
41
52
42
53
Retrieve metadata about specific users:
@@ -53,9 +64,9 @@ final user1 = await client.users.getByUrl('https://www.soundcloud.com/a-user');
53
64
final user2 = await client.users.get(123456789);
54
65
55
66
// Get the tracks/playlists/albums a specific user has uploaded...
56
-
final tracks = client.users.getTracks(user1.id);
57
-
final playlists = client.users.getPlaylists(user1.id);
58
-
final albums = client.users.getAlbums(user1.id);
67
+
final trackStream = client.users.getTracks(user1.id);
68
+
final playlistStream = client.users.getPlaylists(user1.id);
69
+
final albumStream = client.users.getAlbums(user1.id);
0 commit comments