class Campaign { String campaignID; String description; String businessID; String status; String title; DateTime startDate; String targetProduct; int rewards; Campaign({ this.businessID, this.campaignID, this.description, this.rewards, this.startDate, this.status, this.targetProduct, this.title, }); factory Campaign.fromJSON(Map json) { return Campaign( businessID: json["businessId"], campaignID: json["campaignId"], description: json["description"], status: json["status"], title: json["title"], startDate: DateTime.tryParse((json["startDate"].toString())), targetProduct: json["targetProduct"], rewards: int.tryParse((json["rewards"].toString())), ); } Map toJson() { final Map data = Map(); try { data['businessId'] = this.businessID; data['campaignId'] = this.campaignID; data['description'] = this.description; data['status'] = this.status.toString(); data['startDate'] = this.startDate.toString(); data['title'] = this.title; data['targetProduct'] = this.targetProduct; data['rewards'] = this.rewards; } catch (e) { print(e); } return data; } @override String toString() { return '{"businessId": "$businessID", "campaignId": "$campaignID", "description": "$description", "status": "$status",' + '"startDate": "$startDate", "title": "$title", "targetProduct": "$targetProduct", "rewards": "$rewards"}'; } }