diff --git a/lib/src/models/_models.g.dart b/lib/src/models/_models.g.dart index 85b05ce..91ce0bc 100644 --- a/lib/src/models/_models.g.dart +++ b/lib/src/models/_models.g.dart @@ -268,19 +268,10 @@ Map _$StartOrResumeOptionsToJson( 'position_ms': instance.positionMs, }; -UriOffset _$UriOffsetFromJson(Map json) => UriOffset( - json['uri'] as String, - ); - Map _$UriOffsetToJson(UriOffset instance) => { 'uri': instance.uri, }; -PositionOffset _$PositionOffsetFromJson(Map json) => - PositionOffset( - json['position'] as int, - ); - Map _$PositionOffsetToJson(PositionOffset instance) => { 'position': instance.position, diff --git a/lib/src/models/player.dart b/lib/src/models/player.dart index a820e55..90c4e3c 100644 --- a/lib/src/models/player.dart +++ b/lib/src/models/player.dart @@ -144,36 +144,39 @@ class StartOrResumeOptions extends Object { Map toJson() => _$StartOrResumeOptionsToJson(this); static Map _offsetToJson(Offset? offset) { - if (offset is UriOffset) { - return {'uri': offset.uri}; - } else if (offset is PositionOffset) { - return {'position': offset.position}; - } else { - return {}; - } + return offset?.toJson() ?? {}; } } -abstract class Offset {} +abstract class Offset { + Map toJson(); +} /// "uri" is a string representing the uri of the item to start at. /// Example: "spotify:track:1301WleyT98MSxVHPZCA6M" -@JsonSerializable() +@JsonSerializable(createFactory: false) class UriOffset extends Offset { final String uri; UriOffset(this.uri); + + @override + Map toJson() => _$UriOffsetToJson(this); } /// "position" is zero based and can’t be negative. -@JsonSerializable() +@JsonSerializable(createFactory: false) class PositionOffset extends Offset { final int position; PositionOffset(this.position) { assert(position >= 0, 'Position must be greater than or equal to 0'); } + + @override + Map toJson() => _$PositionOffsetToJson(this); } + /// Representation of the current repeat state enum RepeatState { off, context, track }