|
| 1 | +// ignore_for_file: file_names, unused_local_variable, avoid_redundant_argument_values |
| 2 | + |
| 3 | +import 'package:stream_feeds/stream_feeds.dart'; |
| 4 | + |
| 5 | +late StreamFeedsClient client; |
| 6 | +late Feed feed; |
| 7 | + |
| 8 | +Future<void> addingBookmarks() async { |
| 9 | +// Adding a bookmark to a new folder |
| 10 | + final bookmark = await feed.addBookmark(activityId: 'activity_123'); |
| 11 | +// Adding to an existing folder |
| 12 | + final bookmarkWithFolder = await feed.addBookmark( |
| 13 | + activityId: 'activity_123', |
| 14 | + request: const AddBookmarkRequest(folderId: 'folder_456'), |
| 15 | + ); |
| 16 | +// Update a bookmark (without a folder initially) - add custom data and move it to a new folder |
| 17 | + final updatedBookmark = await feed.updateBookmark( |
| 18 | + activityId: 'activity_123', |
| 19 | + request: const UpdateBookmarkRequest( |
| 20 | + custom: {'color': 'blue'}, |
| 21 | + newFolder: AddFolderRequest( |
| 22 | + custom: {'icon': '📁'}, |
| 23 | + name: 'New folder name', |
| 24 | + ), |
| 25 | + ), |
| 26 | + ); |
| 27 | +// Update a bookmark - move it from one existing folder to another existing folder |
| 28 | + final movedBookmark = await feed.updateBookmark( |
| 29 | + activityId: 'activity_123', |
| 30 | + request: const UpdateBookmarkRequest( |
| 31 | + folderId: 'folder_456', |
| 32 | + newFolderId: 'folder_789', |
| 33 | + ), |
| 34 | + ); |
| 35 | +} |
| 36 | + |
| 37 | +Future<void> removingBookmarks() async { |
| 38 | + // Removing a bookmark |
| 39 | + await feed.deleteBookmark(activityId: 'activity_123', folderId: 'folder_456'); |
| 40 | + // When you read a feed we include the bookmark |
| 41 | + final feedData = await feed.getOrCreate(); |
| 42 | + print(feed.state.activities[0].ownBookmarks); |
| 43 | +} |
| 44 | + |
| 45 | +Future<void> queryingBookmarks() async { |
| 46 | + // Query bookmarks |
| 47 | + const query = BookmarksQuery(limit: 5); |
| 48 | + final bookmarkList = client.bookmarkList(query); |
| 49 | + final page1 = await bookmarkList.get(); |
| 50 | + // Get next page |
| 51 | + final page2 = await bookmarkList.queryMoreBookmarks(limit: 3); |
| 52 | + // Query by activity ID |
| 53 | + final activityBookmarkList = client.bookmarkList( |
| 54 | + const BookmarksQuery( |
| 55 | + filter: Filter.equal(BookmarksFilterField.activityId, 'activity_123'), |
| 56 | + ), |
| 57 | + ); |
| 58 | + final activityBookmarks = await activityBookmarkList.get(); |
| 59 | + // Query by folder ID |
| 60 | + final folderBookmarkList = client.bookmarkList( |
| 61 | + const BookmarksQuery( |
| 62 | + filter: Filter.equal(BookmarksFilterField.folderId, 'folder_456'), |
| 63 | + ), |
| 64 | + ); |
| 65 | + final folderBookmarks = await folderBookmarkList.get(); |
| 66 | +} |
| 67 | + |
| 68 | +Future<void> queryingBookmarkFolders() async { |
| 69 | + // Query bookmark folders |
| 70 | + const query = BookmarkFoldersQuery(limit: 5); |
| 71 | + final bookmarkFolderList = client.bookmarkFolderList(query); |
| 72 | + final page1 = await bookmarkFolderList.get(); |
| 73 | + // Get next page |
| 74 | + final page2 = await bookmarkFolderList.queryMoreBookmarkFolders(limit: 3); |
| 75 | + // Query by folder name (partial matching) |
| 76 | + final projectFolderList = client.bookmarkFolderList( |
| 77 | + const BookmarkFoldersQuery( |
| 78 | + filter: Filter.contains(BookmarkFoldersFilterField.name, 'project'), |
| 79 | + ), |
| 80 | + ); |
| 81 | + final projectFolders = await projectFolderList.get(); |
| 82 | +} |
0 commit comments