Created
November 18, 2021 12:41
-
-
Save Jahidul007/98e5ea1107fb9dca0bb7809f558776d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:convert'; | |
void main() { | |
var response = [{ | |
"id": 56012, | |
"name": "a name", | |
"slug": "a slug", | |
"description": "<p>آب آشامیدنی پیورلایف 1/5 لیتری نستله</p>\n", | |
"regular_price": "45000", | |
"sale_price": "45000", | |
"tags": [], | |
}, | |
]; | |
List<ProductModel> items=[]; | |
response.forEach((e){ | |
items.add(ProductModel.fromJson(e)); | |
}); | |
items.forEach((r){ | |
print(r.description); | |
}); | |
} | |
class ProductModel { | |
int id; | |
String name; | |
String slug; | |
String description; | |
String regularPrice; | |
String salePrice; | |
ProductModel( | |
{this.id, | |
this.name, | |
this.slug, | |
this.description, | |
this.regularPrice, | |
this.salePrice}); | |
ProductModel.fromJson(Map<String, dynamic> json) { | |
id = json['id']; | |
name = json['name']; | |
slug = json['slug']; | |
description = json['description']; | |
regularPrice = json['regular_price']; | |
salePrice = json['sale_price']; | |
} | |
Map<String, dynamic> toJson() { | |
final Map<String, dynamic> data = new Map<String, dynamic>(); | |
data['id'] = this.id; | |
data['name'] = this.name; | |
data['slug'] = this.slug; | |
data['description'] = this.description; | |
data['regular_price'] = this.regularPrice; | |
data['sale_price'] = this.salePrice; | |
return data; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment