Skip to content

Instantly share code, notes, and snippets.

@AbhishekDoshi26
Created August 5, 2021 17:24
Show Gist options
  • Save AbhishekDoshi26/c2b5e6b663ab8190384372e208f8ed3a to your computer and use it in GitHub Desktop.
Save AbhishekDoshi26/c2b5e6b663ab8190384372e208f8ed3a to your computer and use it in GitHub Desktop.
import 'dart:convert';
Welcome welcomeFromJson(String str) => Welcome.fromJson(json.decode(str));
String welcomeToJson(Welcome data) => json.encode(data.toJson());
class Welcome {
Welcome({
this.name,
this.age,
this.technology,
});
String name;
int age;
List<Technology> technology;
factory Welcome.fromJson(Map<String, dynamic> json) => Welcome(
name: json.containsKey("name") && json["name"]!=null ? json["name"] : "",
age: json.containsKey("age") && json["age"] ? json["age"] : 0,
technology: json.containsKey("technology") && json["technology"] ? List<Technology>.from(json["technology"].map((x) => Technology.fromJson(x))) : [],
);
Map<String, dynamic> toJson() => {
"name": name,
"age": age,
"technology": List<dynamic>.from(technology.map((x) => x.toJson())),
};
}
class Technology {
Technology({
this.name,
this.experience,
});
String name;
int experience;
factory Technology.fromJson(Map<String, dynamic> json) => Technology(
name: json.containsKey("name") && json["name"]!=null ? json["name"] : "",
experience: json.containsKey("experience") && json["experience"]!=null ? json["experience"] : "",
);
Map<String, dynamic> toJson() => {
"name": name,
"experience": experience,
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment