Comments (3)
This is a good idea, however I suggest, that the cursorAfter
attribute shouldn't be in the Page
-object, rather in its own CursorPage
-object. This would reflect more the spotify object specification. @rinukkusu @chances , what do you think about having a new object CursorPage
that extends the Page
-object?
from spotify-dart.
This is how I solved this while they release a new fixed version, edit the following files of spotify-dart:
_models.g.dart
Paging<T> _$PagingFromJson<T>(Map<String, dynamic> json) {
return Paging<T>()
..href = json['href'] as String
..itemsNative = itemsNativeFromJson(json['items'] as List)
..limit = json['limit'] as int
..next = json['next'] as String
..offset = json['offset'] as int
..previous = json['previous'] as String
..cursorsAfter = json['cursors'] != null ? json['cursors']['after'] as String : null
..total = json['total'] as int;
}
paging.dart
@JsonSerializable(createToJson: false)
class Paging<T> extends Object {
Paging();
factory Paging.fromJson(Map<String, dynamic> json) => _$PagingFromJson(json);
/// A link to the Web API endpoint returning the full result of the request.
String href;
/// The requested data
///
/// Note this is the raw JSON value. Use a [Page]'s [Page.items] to get the
/// requested data as a deserialized list.
@JsonKey(
name: 'items', fromJson: itemsNativeFromJson, toJson: itemsNativeToJson)
Iterable<dynamic> itemsNative;
/// The maximum number of items in the response (as set in the query or by
/// default).
int limit;
/// URL to the next page of items. ([null] if none)
String next;
/// The offset of the items returned (as set in the query or by default).
int offset;
/// URL to the previous page of items. (null if none)
String previous;
/// The total number of items available to return.
int total;
//Cursor used for followers endpoint
String cursorsAfter;
}
endpoint_paging.dart
class Page<T> {
final Paging<T> _paging;
Iterable<T> _items;
Object _container;
Page(this._paging, ParserFunction<T> pageItemParser, [Object pageContainer]) {
_items = _paging.itemsNative.map(pageItemParser);
_container = pageContainer;
}
/// The offset-based paging object is a container for a set of objects. It
/// contains a key called items (whose value is an array of the requested
/// objects) along with other keys like previous, next and limit that can be
/// useful in future calls.
Paging<T> get metadata => _paging;
/// The requested data
Iterable<T> get items => _items;
/// The object containing this page, if applicable
Object get container => _container;
bool get isLast {
if (_paging.offset != null)
return _paging.offset + _paging.limit >= _paging.total;
else
return _paging.next==null;
}
int get nextOffset {
if (_paging.offset != null)
return _paging.offset + _paging.limit;
else
return null;
}
int get totalItems => _paging.total;
String get cursorsAfter => _paging.cursorsAfter;
}
And to obtain the follower here a simple method to use the API:
void getUserFollowing() async {
BundledPages bundeled = await _spotifyApi.me.following(FollowingType.artist);
int limit = 5;
bool readData = true;
List<Page<Object>> pages;
Page<dynamic> currentPage;
while (readData) {
currentPage != null
? pages = await bundeled.getPageAfter(limit, currentPage.cursorsAfter)
: pages = await bundeled.first(limit);
currentPage = pages.first;
readData = !currentPage.isLast;
List<Artist> artists = currentPage.items.toList().cast<Artist>();
for (var artist in artists) {
print(artist.name);
}
}
}
from spotify-dart.
@hayribakici sounds cleaner to me, yes!
from spotify-dart.
Related Issues (20)
- Missing 'album' Field in Recommendations.TrackSimple from recommendations.get API HOT 2
- `DeviceType` 'Smartwatch' is missing
- Playlist info, tracks and artists HOT 10
- Support `episode`s when retrieving items from playlist HOT 1
- Artist Info HOT 2
- startOrResume throws error code 400 (malformed json) HOT 5
- Add debug tools HOT 1
- FormatException HOT 13
- Spotify Client Authentication HOT 3
- Log In Account HOT 13
- 404 Device not found (and unhandled exception) HOT 1
- Bug: `artists.get` throwing exception "type 'double' is not a subtype of type 'int?' in type cast" HOT 20
- An album play something else! HOT 4
- [Question]: Is it possible to have my flutter client read data from my own account HOT 1
- Include `BaseResponseWithUrl` HOT 1
- Expose `codeVerifier` when building `AuthorizationCodeGrant` HOT 4
- Bug: startWithTracks results in error 400 HOT 1
- Bug: `album.tracks` throwing exception "type 'double' is not a subtype of type 'int?' in type cast" HOT 3
- Enable `createToJson` for the models
- Better handling of list of IDs when there are more than 50 HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spotify-dart.