Advertisement
nio74

Untitled

Jan 6th, 2023
1,261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 4.29 KB | None | 0 0
  1. import 'dart:convert';
  2.  
  3. import 'package:equatable/equatable.dart';
  4.  
  5. class RepairDto extends Equatable {
  6.   final int? id_repair;
  7.   final String? customer;
  8.   final DateTime? date_accept;
  9.   final DateTime? date_delive;
  10.   final String? user;
  11.  
  12.   final String? technician;
  13.   final bool? warranty;
  14.   final String? name_image;
  15.   final String? objects;
  16.   final String? works_to_do;
  17.   final double? p_cost;
  18.   final double? p_part1;
  19.   final double? p_part2;
  20.   final double? p_part3;
  21.   final String? note;
  22.   final double? p_public;
  23.   RepairDto({
  24.     this.id_repair,
  25.     this.customer,
  26.     this.date_accept,
  27.     this.date_delive,
  28.     this.user,
  29.     this.technician,
  30.     this.warranty,
  31.     this.name_image,
  32.     this.objects,
  33.     this.works_to_do,
  34.     this.p_cost,
  35.     this.p_part1,
  36.     this.p_part2,
  37.     this.p_part3,
  38.     this.note,
  39.     this.p_public,
  40.   });
  41.  
  42.   RepairDto copyWith({
  43.     int? id_repair,
  44.     String? customer,
  45.     DateTime? date_accept,
  46.     DateTime? date_delive,
  47.     String? user,
  48.     String? technician,
  49.     bool? warranty,
  50.     String? path_image,
  51.     String? objects,
  52.     String? works_to_do,
  53.     double? p_cost,
  54.     double? p_part1,
  55.     double? p_part2,
  56.     double? p_part3,
  57.     String? note,
  58.     double? p_public,
  59.   }) {
  60.     return RepairDto(
  61.       id_repair: id_repair ?? this.id_repair,
  62.       customer: customer ?? this.customer,
  63.       date_accept: date_accept ?? this.date_accept,
  64.       date_delive: date_delive ?? this.date_delive,
  65.       user: user ?? this.user,
  66.       technician: technician ?? this.technician,
  67.       warranty: warranty ?? this.warranty,
  68.       name_image: path_image ?? this.name_image,
  69.       objects: objects ?? this.objects,
  70.       works_to_do: works_to_do ?? this.works_to_do,
  71.       p_cost: p_cost ?? this.p_cost,
  72.       p_part1: p_part1 ?? this.p_part1,
  73.       p_part2: p_part2 ?? this.p_part2,
  74.       p_part3: p_part3 ?? this.p_part3,
  75.       note: note ?? this.note,
  76.       p_public: p_public ?? this.p_public,
  77.     );
  78.   }
  79.  
  80.   Map<String, dynamic> toMap() {
  81.     return {
  82.       'id_repair': id_repair,
  83.       'customer': customer,
  84.       'date_accept': date_accept?.millisecondsSinceEpoch,
  85.       'date_delive': date_delive?.millisecondsSinceEpoch,
  86.       'user': user,
  87.       'technician': technician,
  88.       'warranty': warranty,
  89.       'path_image': name_image,
  90.       'objects': objects,
  91.       'works_to_do': works_to_do,
  92.       'p_cost': p_cost,
  93.       'p_part1': p_part1,
  94.       'p_part2': p_part2,
  95.       'p_part3': p_part3,
  96.       'note': note,
  97.       'p_public': p_public,
  98.     };
  99.   }
  100.  
  101.   factory RepairDto.fromMap(Map<String, dynamic> map) {
  102.     return RepairDto(
  103.       id_repair: map['id_repair']?.toInt(),
  104.       customer: map['customer'],
  105.       date_accept: map['date_accept'] != null
  106.           ? DateTime.fromMillisecondsSinceEpoch(map['date_accept'])
  107.           : null,
  108.       date_delive: map['date_delive'] != null
  109.           ? DateTime.fromMillisecondsSinceEpoch(map['date_delive'])
  110.           : null,
  111.       user: map['user'],
  112.       technician: map['technician'],
  113.       warranty: map['warranty'],
  114.       name_image: map['name_image'],
  115.       objects: map['objects'],
  116.       works_to_do: map['works_to_do'],
  117.       p_cost: map['p_cost']?.toDouble(),
  118.       p_part1: map['p_part1']?.toDouble(),
  119.       p_part2: map['p_part2']?.toDouble(),
  120.       p_part3: map['p_part3']?.toDouble(),
  121.       note: map['note'],
  122.       p_public: map['p_public']?.toDouble(),
  123.     );
  124.   }
  125.  
  126.   String toJson() => json.encode(toMap());
  127.  
  128.   factory RepairDto.fromJson(String source) =>
  129.       RepairDto.fromMap(json.decode(source));
  130.  
  131.   @override
  132.   String toString() {
  133.     return 'RepairDto(id_repair: $id_repair, customer: $customer, date_accept: $date_accept, date_delive: $date_delive, user: $user, technician: $technician, warranty: $warranty, name_image: $name_image, objects: $objects, works_to_do: $works_to_do, p_cost: $p_cost, p_part1: $p_part1, p_part2: $p_part2, p_part3: $p_part3, note: $note, p_public: $p_public)';
  134.   }
  135.  
  136.   @override
  137.   List<Object?> get props {
  138.     return [
  139.       id_repair,
  140.       customer,
  141.       date_accept,
  142.       date_delive,
  143.       user,
  144.       technician,
  145.       warranty,
  146.       name_image,
  147.       objects,
  148.       works_to_do,
  149.       p_cost,
  150.       p_part1,
  151.       p_part2,
  152.       p_part3,
  153.       note,
  154.       p_public,
  155.     ];
  156.   }
  157. }
  158.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement