Skip to content

Instantly share code, notes, and snippets.

Created October 5, 2018 11:56
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Post model GET post/1
// To parse this JSON data, do
// final post = postFromJson(jsonString);
import 'dart:convert';
Post postFromJson(String str) {
final jsonData = json.decode(str);
return Post.fromJson(jsonData);
String postToJson(Post data) {
final dyn = data.toJson();
return json.encode(dyn);
class Post {
int userId;
int id;
String title;
String body;
factory Post.fromJson(Map<String, dynamic> json) => new Post(
userId: json["userId"],
id: json["id"],
title: json["title"],
body: json["body"],
Map<String, dynamic> toJson() => {
"userId": userId,
"id": id,
"title": title,
"body": body,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment