palm_record.dart 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import 'dart:convert';
  2. class PalmRecord {
  3. final int? id;
  4. final String imagePath;
  5. final String ripenessClass;
  6. final double confidence;
  7. final DateTime timestamp;
  8. final double x1;
  9. final double y1;
  10. final double x2;
  11. final double y2;
  12. final List<Map<String, dynamic>> detections;
  13. PalmRecord({
  14. this.id,
  15. required this.imagePath,
  16. required this.ripenessClass,
  17. required this.confidence,
  18. required this.timestamp,
  19. required this.x1,
  20. required this.y1,
  21. required this.x2,
  22. required this.y2,
  23. this.detections = const [],
  24. });
  25. Map<String, dynamic> toMap() {
  26. return {
  27. 'id': id,
  28. 'image_path': imagePath,
  29. 'ripeness_class': ripenessClass,
  30. 'confidence': confidence,
  31. 'timestamp': timestamp.toIso8601String(),
  32. 'x1': x1,
  33. 'y1': y1,
  34. 'x2': x2,
  35. 'y2': y2,
  36. 'detections': json.encode(detections),
  37. };
  38. }
  39. factory PalmRecord.fromMap(Map<String, dynamic> map) {
  40. return PalmRecord(
  41. id: map['id'],
  42. imagePath: map['image_path'],
  43. ripenessClass: map['ripeness_class'],
  44. confidence: map['confidence'],
  45. timestamp: DateTime.parse(map['timestamp']),
  46. x1: map['x1'],
  47. y1: map['y1'],
  48. x2: map['x2'],
  49. y2: map['y2'],
  50. detections: map['detections'] != null
  51. ? List<Map<String, dynamic>>.from(json.decode(map['detections']))
  52. : [],
  53. );
  54. }
  55. String toJson() => json.encode(toMap());
  56. factory PalmRecord.fromJson(String source) => PalmRecord.fromMap(json.decode(source));
  57. }