Houshan-Basa/lib/data/model/courses_model.dart

108 lines
2.2 KiB
Dart

class Courses {
int? id;
String? name;
String? permalink;
String? dateCreated;
String? shortDescription;
String? price;
String? regularPrice;
String? salePrice;
List<CourseImage>? images;
List<Category>? categories;
Courses({
this.id,
this.name,
this.permalink,
this.dateCreated,
this.shortDescription,
this.price,
this.regularPrice,
this.salePrice,
this.images,
this.categories,
});
factory Courses.fromJson(Map<String, dynamic> json) {
return Courses(
id: json['id'],
name: json['name'],
permalink: json['permalink'],
dateCreated: json['date_created'],
shortDescription: json['short_description'],
price: json['price'],
regularPrice: json['regular_price'],
salePrice: json['sale_price'],
images: json['images'] != null
? (json['images'] as List)
.map((i) => CourseImage.fromJson(i))
.toList()
: null,
categories: json['categories'] != null
? (json['categories'] as List)
.map((i) => Category.fromJson(i))
.toList()
: null,
);
}
Map<String, dynamic> toJson() {
return {
'id': id,
'name': name,
'permalink': permalink,
'date_created': dateCreated,
'short_description': shortDescription,
'price': price,
'regular_price': regularPrice,
'sale_price': salePrice,
'images': images?.map((i) => i.toJson()).toList(),
};
}
}
class Category {
int? id;
Category({this.id});
factory Category.fromJson(Map<String, dynamic> json) {
return Category(
id: json['id'],
);
}
Map<String, dynamic> toJson() {
return {
'id': id,
};
}
}
class CourseImage {
int? id;
String? src;
String? name;
String? alt;
CourseImage({this.id, this.src, this.name, this.alt});
factory CourseImage.fromJson(Map<String, dynamic> json) {
return CourseImage(
id: json['id'],
src: json['src'],
name: json['name'],
alt: json['alt'],
);
}
Map<String, dynamic> toJson() {
return {
'id': id,
'src': src,
'name': name,
'alt': alt,
};
}
}