Created
November 24, 2021 14:20
-
-
Save ctkqiang/56b09d62af9de1f15ff682fd2722c341 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ignore_for_file: non_constant_identifier_names | |
import 'dart:convert'; | |
List<UserPostsModel> userPostsFromJson(String str) { | |
return List<UserPostsModel>.from(json.decode(str).map((x) { | |
return UserPostsModel.fromJson(x); | |
})); | |
} | |
String userPostsToJson(List<UserPostsModel> data) { | |
return json.encode(List<UserPostsModel>.from(data.map((x) { | |
return x.toJson(); | |
}))); | |
} | |
class UserPostsModel { | |
int? id; | |
String? email; | |
String? amount; | |
String? description; | |
String? image; | |
String? token; | |
String? category; | |
DateTime? created_at; | |
UserPostsModel({ | |
this.id, | |
this.email, | |
this.amount, | |
this.description, | |
this.image, | |
this.token, | |
this.category, | |
this.created_at, | |
}); | |
factory UserPostsModel.fromJson(json) { | |
return UserPostsModel( | |
id: json['id'], | |
email: json['email'], | |
amount: json['amount'], | |
description: json['dbescription'], | |
image: json['image'], | |
token: json['token'], | |
category: json['category'], | |
created_at: DateTime.parse(json["created_at"]), | |
); | |
} | |
Map<String, dynamic> toJson() { | |
return { | |
"id": id, | |
"email": email, | |
"amount": amount, | |
"description": description, | |
"image": image, | |
"token": token, | |
"category": category, | |
"created_at": created_at?.toIso8601String(), | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment