import 'package:json_annotation/json_annotation.dart'; part 'stream.g.dart'; // Object for live Twitch streams. @JsonSerializable(createToJson: false, fieldRename: FieldRename.snake) class StreamTwitch { final String userId; final String userLogin; final String userName; final String gameId; final String gameName; final String title; final int viewerCount; final String startedAt; final String thumbnailUrl; /// ISO 639-1 broadcast language from Helix (`de`, `en`, …). Empty when unknown. @JsonKey(defaultValue: '') final String language; /// Freeform tags from Helix (e.g. `Deutsch`, `English`). @JsonKey(defaultValue: []) final List tags; const StreamTwitch( this.userId, this.userLogin, this.userName, this.gameId, this.gameName, this.title, this.viewerCount, this.startedAt, this.thumbnailUrl, [ this.language = '', this.tags = const [], ]); factory StreamTwitch.fromJson(Map json) => _$StreamTwitchFromJson(json); } @JsonSerializable(createToJson: false, fieldRename: FieldRename.snake) class StreamsTwitch { final List data; final Map pagination; const StreamsTwitch(this.data, this.pagination); factory StreamsTwitch.fromJson(Map json) { final rawPagination = json['pagination']; final pagination = {}; if (rawPagination is Map) { final cursor = rawPagination['cursor']; if (cursor is String && cursor.isNotEmpty) { pagination['cursor'] = cursor; } } return StreamsTwitch( (json['data'] as List) .map((e) => StreamTwitch.fromJson(e as Map)) .toList(), pagination, ); } }