import 'package:json_annotation/json_annotation.dart'; import 'package:uuid/uuid.dart'; @JsonSerializable(createToJson: false) class AlbumDto { final List? data; final AlbumPaginationDto? pagination; // Добавлено для пагинации const AlbumDto({this.data, this.pagination}); // Здесь убираем factory и оставляем ваш метод fetchAlbums // factory AlbumDto.fromJson(Map json) => _$AlbumDtoFromJson(json); // Ваш метод fetchAlbums будет принимать JSON и вызывать конструктор static AlbumDto fetchAlbums(Map json) { return AlbumDto( data: (json['data'] as List?) ?.map((e) => AlbumDataDto.fromJson(e as Map)) .toList(), pagination: json['pagination'] != null ? AlbumPaginationDto.fromJson(json['pagination']) : null, ); } } @JsonSerializable(createToJson: false) class AlbumPaginationDto { @JsonKey(name: 'current_page') final int? currentPage; @JsonKey(name: 'has_next_page') final bool? hasNextPage; @JsonKey(name: 'last_visible_page') final int? lastVisiblePage; const AlbumPaginationDto({this.currentPage, this.hasNextPage, this.lastVisiblePage}); // Здесь убираем factory // factory AlbumPaginationDto.fromJson(Map json) => _$AlbumPaginationDtoFromJson(json); // Метод для конструирования экземпляра static AlbumPaginationDto fromJson(Map json) { return AlbumPaginationDto( currentPage: json['current_page'], hasNextPage: json['has_next_page'], lastVisiblePage: json['last_visible_page'], ); } } @JsonSerializable(createToJson: false) class AlbumDataDto { final String id; final String? title; final String? artist; String? year; List? genres; List? tracks; String? summary; String? url; final AlbumDataImagesDto? images; AlbumDataDto({ String? id, this.title, this.artist, this.year, this.genres, this.tracks, this.summary, this.url, this.images, }) : id = id ?? const Uuid().v4(); // Генерация id // Здесь убираем factory // factory AlbumDataDto.fromJson(Map json) => _$AlbumDataDtoFromJson(json); // Метод для конструирования экземпляра static AlbumDataDto fromJson(Map json) { return AlbumDataDto( id: json['id'], title: json['title'], artist: json['artist'], year: json['year'], genres: (json['genres'] as List?)?.map((e) => e as String).toList(), tracks: (json['tracks'] as List?)?.map((e) => e as String).toList(), summary: json['summary'], url: json['url'], images: json['images'] != null ? AlbumDataImagesDto.fromJson(json['images']) : null, ); } } @JsonSerializable(createToJson: false) class AlbumDataImagesDto { final AlbumDataImagesJPGDto? jpg; const AlbumDataImagesDto({this.jpg}); // Здесь убираем factory // factory AlbumDataImagesDto.fromJson(Map json) => _$AlbumDataImagesDtoFromJson(json); // Метод для конструирования экземпляра static AlbumDataImagesDto fromJson(Map json) { return AlbumDataImagesDto( jpg: json['jpg'] != null ? AlbumDataImagesJPGDto.fromJson(json['jpg']) : null, ); } } @JsonSerializable(createToJson: false) class AlbumDataImagesJPGDto { final String? image_url; const AlbumDataImagesJPGDto({this.image_url}); // Здесь убираем factory // factory AlbumDataImagesJPGDto.fromJson(Map json) => _$AlbumDataImagesJPGDtoFromJson(json); // Метод для конструирования экземпляра static AlbumDataImagesJPGDto fromJson(Map json) { return AlbumDataImagesJPGDto( image_url: json['image_url'], ); } }