import 'dart:convert'; T? asT(dynamic value) { if (value is T) { return value; } return null; } class NewsBannerModel { NewsBannerModel({ required this.id, required this.title, required this.picUrl, this.objectId, this.objectUrl, }); factory NewsBannerModel.fromJson(Map json) => NewsBannerModel( id: asT(json['id'])!, title: asT(json['title'])!, picUrl: asT(json['pic_url'])!, objectId: asT(json['object_id']), objectUrl: asT(json['object_url']), ); int id; String title; String picUrl; int? objectId; String? objectUrl; @override String toString() { return jsonEncode(this); } Map toJson() => { 'id': id, 'title': title, 'pic_url': picUrl, 'object_id': objectId, 'object_url': objectUrl, }; }