Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'dart:convert';
- class Product {
- int id;
- String nama;
- int harga;
- String jenis;
- String photo;
- String idUser;
- Product(
- {this.id = 0,
- this.nama,
- this.harga,
- this.jenis,
- this.photo,
- this.idUser});
- factory Product.fromJson(Map<String, dynamic> map) {
- return Product(
- id: map['id'],
- nama: map['nama'],
- harga: map['harga'],
- jenis: map['jenis'],
- photo: map['photo'],
- idUser: map['id_user']);
- }
- Map<String, dynamic> toJson() {
- return {
- 'id': id,
- 'nama': nama,
- 'harga': harga,
- 'jenis': jenis,
- 'photo': photo,
- 'idUserr': idUser
- };
- }
- String toString() {
- return 'Product{id: $id, name: $nama, harga: $harga, jenis: $jenis, photo: $photo, idUser: $idUser}';
- }
- }
- List<Product> productFromJson(String jsonData) {
- final data = json.decode(jsonData);
- return List<Product>.from(data.map((item) => {Product.fromJson(item)}));
- }
- String productToJson(Product data) {
- final jsonData = data.toJson();
- return json.encode(jsonData);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement