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.
50 lines
1.5 KiB
Dart
50 lines
1.5 KiB
Dart
import 'package:test_sa/extensions/enum_extensions.dart';
|
|
import 'package:test_sa/models/enums/work_order_next_step.dart';
|
|
|
|
import 'base.dart';
|
|
|
|
class Lookup extends Base {
|
|
int? id; // Now nullable
|
|
int? value; // Now nullable
|
|
WorkOrderNextStepEnum? workOrderNextStepEnum; // Now nullable
|
|
String? name; // Now nullable
|
|
|
|
Lookup({this.id, this.value, this.name, this.workOrderNextStepEnum}) : super(identifier: id?.toString(), name: name);
|
|
|
|
@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; // Use XOR for hash code combination
|
|
|
|
Map<String, dynamic> toJson() {
|
|
// Return a Map instead of calling a function
|
|
return {"id": id, "name": name, "value": value};
|
|
}
|
|
|
|
static Lookup? fromStatus(Lookup? old) {
|
|
// Now accepts nullable Lookup and returns nullable Lookup
|
|
if (old == null) return null;
|
|
return Lookup(
|
|
name: old.name,
|
|
id: old.id,
|
|
value: old.value,
|
|
);
|
|
}
|
|
|
|
// CreatedBy.fromJson(dynamic json) {
|
|
// userId = json['userId'] ?? '';
|
|
// userName = json['userName'] ?? '';
|
|
// }
|
|
|
|
factory Lookup.fromJson(Map<String, dynamic>? parsedJson) {
|
|
if(parsedJson==null) return Lookup();
|
|
return Lookup(
|
|
name: parsedJson["name"],
|
|
workOrderNextStepEnum: parsedJson["value"] == null ? null : (parsedJson["value"] as int).toWorkOrderNextStepEnum(),
|
|
id: parsedJson["id"],
|
|
value: parsedJson["value"],
|
|
);
|
|
}
|
|
}
|