You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cloudsolutions-atoms/lib/models/lookup.dart

67 lines
1.4 KiB
Dart

class Lookup{
//old name label
final String name;
// old name key
final int value;
final int id;
const Lookup({
this.name,
this.value,
this.id,
});
@override
bool operator == (Object other) =>
identical(this, other) || other is Lookup &&
((value != null && value == other.value)
|| ( id != null && id == other.id )) ;
@override
int get hashCode => id?.hashCode ?? value?.hashCode;
toMap(){
return {
"id": id,
"name": name,
"value": value
};
}
factory Lookup.fromStatus(Lookup old){
if(old == null) return null;
return Lookup(
name: old.name,
id: old.id,
value: old.value,
);
}
factory Lookup.fromJson(Map<String,dynamic> parsedJson){
if(parsedJson == null) return null;
return Lookup(
name: parsedJson["name"],
id: parsedJson["id"],
value: parsedJson["value"] ?? parsedJson["id"],
);
}
// factory Lookup.fromJson(Map<String,dynamic> parsedJson){
// if(parsedJson["id"] == null && parsedJson["uid"] == null) return null;
// return Lookup(
// name: parsedJson["value"],
// id: parsedJson["id"] is int
// ? parsedJson["id"]
// : int.tryParse(parsedJson["id"] ?? parsedJson["uid"]),
// );
// }
factory Lookup.fromIntIdJson(Map<String,dynamic> parsedJson){
return Lookup(
name: parsedJson["value"],
id: parsedJson["id"],
);
}
}