48 lines
1.3 KiB
Dart
48 lines
1.3 KiB
Dart
// Assumiamo che la classe PlantVariety sia stata definita in un file 'plant_variety.dart'
|
|
import 'plant.variety.dart';
|
|
|
|
class VinePlant {
|
|
// Proprietà della classe
|
|
final int id;
|
|
final int rowId;
|
|
final int plantNumberInRow;
|
|
final int varietyId;
|
|
final PlantVariety variety;
|
|
final DateTime plantingDate;
|
|
|
|
// Costruttore con parametri nominati
|
|
VinePlant({
|
|
required this.id,
|
|
required this.rowId,
|
|
required this.plantNumberInRow,
|
|
required this.varietyId,
|
|
required this.variety,
|
|
required this.plantingDate,
|
|
});
|
|
|
|
// ---
|
|
|
|
/// Converte l'oggetto VinePlant in una mappa per la serializzazione JSON.
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'id': id,
|
|
'rowId': rowId,
|
|
'plantNumberInRow': plantNumberInRow,
|
|
'varietyId': varietyId,
|
|
'variety': variety.toJson(),
|
|
'plantingDate': plantingDate.toIso8601String(),
|
|
};
|
|
}
|
|
|
|
/// Crea un oggetto VinePlant da una mappa (es. da una risposta JSON).
|
|
factory VinePlant.fromJson(Map<String, dynamic> json) {
|
|
return VinePlant(
|
|
id: json['id'] as int,
|
|
rowId: json['rowId'] as int,
|
|
plantNumberInRow: json['plantNumberInRow'] as int,
|
|
varietyId: json['varietyId'] as int,
|
|
variety: PlantVariety.fromJson(json['variety'] as Map<String, dynamic>),
|
|
plantingDate: DateTime.parse(json['plantingDate'] as String),
|
|
);
|
|
}
|
|
} |