import 'package:equatable/equatable.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:selfprivacy/models/item.dart'; part 'order.g.dart'; @JsonSerializable() class Order { factory Order.fromJson(final Map json) => _$OrderFromJson(json); Order({ required this.title, required this.description, required this.id, required this.customerName, required this.customerPhone, required this.orderDate, required this.deliveryDate, required this.address, required this.status, required this.courierId, required this.items, }); final String title; final String description; @JsonKey(name: 'customer_name') final String customerName; @JsonKey(name: 'customer_phone') final String customerPhone; @JsonKey(name: 'order_date') final String orderDate; @JsonKey(name: 'delivery_date') final String deliveryDate; final String address; final String status; final int id; final int courierId; final List items; // tojson Map toJson() => _$OrderToJson(this); Map toJsonAsNew() { final Map data = _$OrderToJson(this); // To "order_in" goes everything except items data['order_in'] = { 'title': data['title'], 'description': data['description'], 'customer_name': data['customer_name'], 'customer_phone': data['customer_phone'], 'order_date': data['order_date'], 'delivery_date': data['delivery_date'], 'address': data['address'], 'status': data['status'], 'courier_id': data['courier_id'], }; // To "order_items" goes only items data['order_items'] = data['items']; // Remove items from data data.remove('items'); return data; } }