| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284 |
- import 'package:news_app/extension/base.dart';
- class NewsDataModel {
- NewsDataModel({
- List<NewsRecord>? records,
- int? total,
- int? size,
- int? current,
- int? pages,
- }) {
- _records = records;
- _total = total;
- _size = size;
- _current = current;
- _pages = pages;
- }
- NewsDataModel.fromJson(dynamic json) {
- if (json['records'] != null) {
- _records = [];
- json['records'].forEach((v) {
- _records?.add(NewsRecord.fromJson(v));
- });
- }
- _total = json['total'].toString().convertInt;
- _size = json['size'].toString().convertInt;
- _current = json['current'].toString().convertInt;
- _pages = json['pages'].toString().convertInt;
- }
- List<NewsRecord>? _records;
- int? _total;
- int? _size;
- int? _current;
- int? _pages;
- NewsDataModel copyWith({
- List<NewsRecord>? records,
- int? total,
- int? size,
- int? current,
- int? pages,
- }) => NewsDataModel(
- records: records ?? _records,
- total: total ?? _total,
- size: size ?? _size,
- current: current ?? _current,
- pages: pages ?? _pages,
- );
- List<NewsRecord>? get records => _records;
- int? get total => _total;
- int? get size => _size;
- int? get current => _current;
- int? get pages => _pages;
- Map<String, dynamic> toJson() {
- final map = <String, dynamic>{};
- if (_records != null) {
- map['records'] = _records?.map((v) => v.toJson()).toList();
- }
- map['total'] = _total;
- map['size'] = _size;
- map['current'] = _current;
- map['pages'] = _pages;
- return map;
- }
- }
- class NewsRecord {
- NewsRecord({
- String? contentId,
- String? catalogId,
- String? contentType,
- String? title,
- String? logo,
- List<String>? images,
- List<String>? imagesSrc,
- String? author,
- String? editor,
- String? summary,
- List<String>? attributes,
- String? topFlag,
- List<String>? keywords,
- List<String>? tags,
- String? publishDateStr,
- String? likeCount,
- String? commentCount,
- String? favoriteCount,
- String? viewCount,
- bool? isLiked,
- bool? isFavorite,
- }) {
- _contentId = contentId;
- _catalogId = catalogId;
- _contentType = contentType;
- _title = title;
- _logo = logo;
- _images = images;
- _imagesSrc = imagesSrc;
- _author = author;
- _editor = editor;
- _summary = summary;
- _attributes = attributes;
- _topFlag = topFlag;
- _keywords = keywords;
- _tags = tags;
- _publishDateStr = publishDateStr;
- _likeCount = likeCount;
- _commentCount = commentCount;
- _favoriteCount = favoriteCount;
- _viewCount = viewCount;
- _isLiked = isLiked;
- _isFavorite = isFavorite;
- }
- NewsRecord.fromJson(dynamic json) {
- _contentId = json['contentId'];
- _catalogId = json['catalogId'];
- _contentType = json['contentType'];
- _title = json['title'];
- _logo = json['logo'];
- _images = json['images'] != null ? json['images'].cast<String>() : [];
- _imagesSrc =
- json['imagesSrc'] != null ? json['imagesSrc'].cast<String>() : [];
- _author = json['author'];
- _editor = json['editor'];
- _summary = json['summary'];
- _attributes =
- json['attributes'] != null ? json['attributes'].cast<String>() : [];
- _topFlag = json['topFlag'];
- _keywords = json['keywords'] != null ? json['keywords'].cast<String>() : [];
- _tags = json['tags'] != null ? json['tags'].cast<String>() : [];
- _publishDateStr = json['publishDateStr'];
- _likeCount = json['likeCount'];
- _commentCount = json['commentCount'];
- _favoriteCount = json['favoriteCount'];
- _viewCount = json['viewCount'];
- _isLiked = json['isLiked'];
- _isFavorite = json['isFavorite'];
- }
- String? _contentId;
- String? _catalogId;
- String? _contentType;
- String? _title;
- String? _logo;
- List<String>? _images;
- List<String>? _imagesSrc;
- String? _author;
- String? _editor;
- String? _summary;
- List<String>? _attributes;
- String? _topFlag;
- List<String>? _keywords;
- List<String>? _tags;
- String? _publishDateStr;
- String? _likeCount;
- String? _commentCount;
- String? _favoriteCount;
- String? _viewCount;
- bool? _isLiked;
- bool? _isFavorite;
- NewsRecord copyWith({
- String? contentId,
- String? catalogId,
- String? contentType,
- String? title,
- String? logo,
- List<String>? images,
- List<String>? imagesSrc,
- String? author,
- String? editor,
- String? summary,
- List<String>? attributes,
- String? topFlag,
- List<String>? keywords,
- List<String>? tags,
- String? publishDateStr,
- String? likeCount,
- String? commentCount,
- String? favoriteCount,
- String? viewCount,
- bool? isLiked,
- bool? isFavorite,
- }) => NewsRecord(
- contentId: contentId ?? _contentId,
- catalogId: catalogId ?? _catalogId,
- contentType: contentType ?? _contentType,
- title: title ?? _title,
- logo: logo ?? _logo,
- images: images ?? _images,
- imagesSrc: imagesSrc ?? _imagesSrc,
- author: author ?? _author,
- editor: editor ?? _editor,
- summary: summary ?? _summary,
- attributes: attributes ?? _attributes,
- topFlag: topFlag ?? _topFlag,
- keywords: keywords ?? _keywords,
- tags: tags ?? _tags,
- publishDateStr: publishDateStr ?? _publishDateStr,
- likeCount: likeCount ?? _likeCount,
- commentCount: commentCount ?? _commentCount,
- favoriteCount: favoriteCount ?? _favoriteCount,
- viewCount: viewCount ?? _viewCount,
- isLiked: isLiked ?? _isLiked,
- isFavorite: isFavorite ?? _isFavorite,
- );
- String? get contentId => _contentId;
- String? get catalogId => _catalogId;
- String? get contentType => _contentType;
- String? get title => _title;
- String? get logo => _logo;
- List<String>? get images => _images;
- List<String>? get imagesSrc => _imagesSrc;
- String? get author => _author;
- String? get editor => _editor;
- String? get summary => _summary;
- List<String>? get attributes => _attributes;
- String? get topFlag => _topFlag;
- List<String>? get keywords => _keywords;
- List<String>? get tags => _tags;
- String? get publishDateStr => _publishDateStr;
- String? get likeCount => _likeCount;
- String? get commentCount => _commentCount;
- String? get favoriteCount => _favoriteCount;
- String? get viewCount => _viewCount;
- bool? get isLiked => _isLiked;
- bool? get isFavorite => _isFavorite;
- Map<String, dynamic> toJson() {
- final map = <String, dynamic>{};
- map['contentId'] = _contentId;
- map['catalogId'] = _catalogId;
- map['contentType'] = _contentType;
- map['title'] = _title;
- map['logo'] = _logo;
- map['images'] = _images;
- map['imagesSrc'] = _imagesSrc;
- map['author'] = _author;
- map['editor'] = _editor;
- map['summary'] = _summary;
- map['attributes'] = _attributes;
- map['topFlag'] = _topFlag;
- if (_keywords != null) {
- map['keywords'] = _keywords;
- }
- map['tags'] = _tags;
- map['publishDateStr'] = _publishDateStr;
- map['likeCount'] = _likeCount;
- map['commentCount'] = _commentCount;
- map['favoriteCount'] = _favoriteCount;
- map['viewCount'] = _viewCount;
- map['isLiked'] = _isLiked;
- map['isFavorite'] = _isFavorite;
- return map;
- }
- }
|