Fix Dart2 default template (#3790)

* fix dart2 default template

* update dart samples
This commit is contained in:
William Cheng
2019-08-29 15:10:19 +08:00
committed by GitHub
parent e4b39ce95e
commit 8236424aff
44 changed files with 600 additions and 330 deletions

View File

@@ -43,5 +43,16 @@ class ApiResponse {
}
return map;
}
// maps a json object with a list of ApiResponse-objects as value to a dart map
static Map<String, List<ApiResponse>> mapListFromJson(Map<String, dynamic> json) {
var map = Map<String, List<ApiResponse>>();
if (json != null && json.isNotEmpty) {
json.forEach((String key, dynamic value) {
map[key] = ApiResponse.listFromJson(value);
});
}
return map;
}
}

View File

@@ -38,5 +38,16 @@ class Category {
}
return map;
}
// maps a json object with a list of Category-objects as value to a dart map
static Map<String, List<Category>> mapListFromJson(Map<String, dynamic> json) {
var map = Map<String, List<Category>>();
if (json != null && json.isNotEmpty) {
json.forEach((String key, dynamic value) {
map[key] = Category.listFromJson(value);
});
}
return map;
}
}

View File

@@ -61,5 +61,16 @@ class Order {
}
return map;
}
// maps a json object with a list of Order-objects as value to a dart map
static Map<String, List<Order>> mapListFromJson(Map<String, dynamic> json) {
var map = Map<String, List<Order>>();
if (json != null && json.isNotEmpty) {
json.forEach((String key, dynamic value) {
map[key] = Order.listFromJson(value);
});
}
return map;
}
}

View File

@@ -65,5 +65,16 @@ class Pet {
}
return map;
}
// maps a json object with a list of Pet-objects as value to a dart map
static Map<String, List<Pet>> mapListFromJson(Map<String, dynamic> json) {
var map = Map<String, List<Pet>>();
if (json != null && json.isNotEmpty) {
json.forEach((String key, dynamic value) {
map[key] = Pet.listFromJson(value);
});
}
return map;
}
}

View File

@@ -38,5 +38,16 @@ class Tag {
}
return map;
}
// maps a json object with a list of Tag-objects as value to a dart map
static Map<String, List<Tag>> mapListFromJson(Map<String, dynamic> json) {
var map = Map<String, List<Tag>>();
if (json != null && json.isNotEmpty) {
json.forEach((String key, dynamic value) {
map[key] = Tag.listFromJson(value);
});
}
return map;
}
}

View File

@@ -68,5 +68,16 @@ class User {
}
return map;
}
// maps a json object with a list of User-objects as value to a dart map
static Map<String, List<User>> mapListFromJson(Map<String, dynamic> json) {
var map = Map<String, List<User>>();
if (json != null && json.isNotEmpty) {
json.forEach((String key, dynamic value) {
map[key] = User.listFromJson(value);
});
}
return map;
}
}