class ConditionPetiModel { int? id; String? nama_kondisi; String? deskripsi_kondisi; DateTime? created_at; DateTime? updated_at; DateTime? deleted_at; String? created_by; String? updated_by; ConditionPetiModel({ this.id, this.nama_kondisi, this.deskripsi_kondisi, this.created_at, this.updated_at, this.deleted_at, this.created_by, this.updated_by, }); factory ConditionPetiModel.fromJson(Map json) { return ConditionPetiModel( id: json['id'], nama_kondisi: json['nama_kondisi'], deskripsi_kondisi: json['deskripsi_kondisi'], created_at: parseDateTime(json['created_at']), updated_at: parseDateTime(json['updated_at']), deleted_at: parseDateTime(json['deleted_at']), created_by: json['created_by'].toString(), updated_by: json['updated_by'].toString(), ); } Map toJson() => { 'id': id, 'nama_kondisi': nama_kondisi, 'deskripsi_kondisi': deskripsi_kondisi, 'created_by': created_by.toString(), 'updated_by': updated_by.toString(), 'created_at': created_at?.toIso8601String(), 'updated_at': updated_at?.toIso8601String(), 'deleted_at': deleted_at?.toIso8601String(), }; static DateTime? parseDateTime(String? dateTimeString) { if (dateTimeString != null && dateTimeString.isNotEmpty) { try { return DateTime.parse(dateTimeString); } catch (e) { print('Error parsing DateTime: $e'); } } return null; } }