123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- /// Modelo de datos para retener la informacion basica necesaria de todos los modelos
- class Basico {
- static const String identificadorLocal = "idLocal";
- static const String identificadorWeb = "id";
- int id;
- int idLocal;
- DateTime? creado;
- DateTime? modificado;
- DateTime? eliminado;
- Basico({
- this.id = 0,
- this.idLocal = -1,
- this.creado,
- this.modificado,
- this.eliminado,
- });
- static parseDate(origen) {
- if (origen == null || origen == "null" || origen == '') {
- return null;
- }
- try {
- return DateTime.parse(origen);
- } catch (e) {
- print("Error al parsear fecha: $e");
- return null;
- }
- }
- static double parseDouble(origen) {
- if (origen == null) return 0.0;
- if (origen == "null") return 0.0;
- if (origen == "") return 0.0;
- if (origen.runtimeType.toString() == 'double') return origen;
- return double.parse(origen.toString());
- }
- static int parseInt(origen) {
- if (origen == null) return 0;
- if (origen == "") return 0;
- if (origen == "null") return 0;
- if (origen.runtimeType.toString() == 'int') return origen;
- return int.parse(origen.toString());
- }
- static String parseString(origen) {
- if (origen == "null") return "";
- if (origen == null) return "";
- if (origen == "") return "";
- if (origen == "null") return "";
- if (origen.runtimeType.toString() == 'string') return origen;
- return origen.toString();
- }
- static bool parseBolean(origen) {
- if (origen == null) return false;
- if (origen == "") return false;
- if (origen == "null") return false;
- if (origen == "false") return false;
- if (origen.runtimeType.toString() == 'bool') return origen;
- return bool.parse(origen.toString());
- }
- Map<String, dynamic> toJson() {
- return {
- 'id': id,
- 'idLocal': idLocal,
- 'eliminado': eliminado,
- };
- }
- parseJson(Map<String, dynamic> json) {
- id = json['id'] != null ? int.parse(json['id'].toString()) : 0;
- idLocal = json['idLocal'] ?? -1;
- creado = json['creado'] != null ? parseDate(json['creado']) : creado;
- modificado =
- json['modificado'] != null ? parseDate(json['modificado']) : modificado;
- eliminado =
- json['eliminado'] != null ? parseDate(json['eliminado']) : eliminado;
- }
- }
|