Skip to content

Instantly share code, notes, and snippets.

@red-star25
Created January 6, 2022 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save red-star25/e1252565070a23f3cc4d042f46b32679 to your computer and use it in GitHub Desktop.
Save red-star25/e1252565070a23f3cc4d042f46b32679 to your computer and use it in GitHub Desktop.
JokeModel jokeModelFromJson(String str) => JokeModel.fromJson(json.decode(str));
String jokeModelToJson(JokeModel data) => json.encode(data.toJson());
class JokeModel {
JokeModel({
required this.setup,
required this.delivery,
required this.id,
});
String setup;
String delivery;
int id;
factory JokeModel.fromJson(Map<String, dynamic> json) => JokeModel(
setup: json["setup"] ?? json["joke"],
delivery: json["delivery"] ?? "",
id: json["id"],
);
Map<String, dynamic> toJson() => {
"setup": setup,
"delivery": delivery,
"id": id,
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment