Files
hackathon-innovaflow5.0-cdf…/recolecta_app/lib/core/models/colonia.dart
shinra32 21a73162df Co-authored-by: MENDOZA BALLARDO GAEL RICARDO <gael-meb123@users.noreply.github.com>
Co-authored-by: Azareth-Tr <Azareth-Tr@users.noreply.githu

b.com>

correcion de errores en llenado de tablas, primeras vistas frontend
2026-05-22 20:17:04 -06:00

64 lines
1.5 KiB
Dart

class Colonia {
const Colonia({
required this.id,
required this.nombre,
this.routeId,
this.horarioEstimado,
this.turno,
});
final String id;
final String nombre;
final String? routeId;
final String? horarioEstimado;
final String? turno;
factory Colonia.fromJson(Map<String, dynamic> json) {
final rawNombre = _pickString(<dynamic>[
json['nombre'],
json['colonia'],
json['name'],
]);
final rawRouteId = _pickString(<dynamic>[
json['routeId'],
json['route_id'],
]);
final rawId = _pickString(<dynamic>[json['id'], rawRouteId, rawNombre]);
return Colonia(
id: rawId ?? '',
nombre: rawNombre ?? rawId ?? '',
routeId: rawRouteId,
horarioEstimado: _pickString(<dynamic>[
json['horario_estimado'],
json['horarioEstimado'],
json['schedule'],
]),
turno: _pickString(<dynamic>[json['turno'], json['shift']]),
);
}
Map<String, dynamic> toJson() {
return <String, dynamic>{
'id': id,
'nombre': nombre,
'routeId': routeId,
'horario_estimado': horarioEstimado,
'turno': turno,
};
}
static String? _pickString(Iterable<dynamic> candidates) {
for (final candidate in candidates) {
if (candidate is String && candidate.isNotEmpty) {
return candidate;
}
if (candidate != null && candidate.toString().isNotEmpty) {
return candidate.toString();
}
}
return null;
}
}