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/gas_refill/gas_refill_model.dart

55 lines
1.4 KiB
Dart

3 years ago
import '../lookup.dart';
import 'gas_refill_details.dart';
3 years ago
3 years ago
class GasRefillModel {
String? id;
String? userId;
String? clientName;
String? title;
Lookup? status;
List<GasRefillDetails>? details;
3 years ago
GasRefillModel({
this.id,
this.userId,
this.clientName,
this.title,
this.status,
this.details,
});
3 years ago
bool validate() {
if (title == null) return false;
if (status == null) return false;
if (details == null && (details?.isEmpty ?? true)) return false;
3 years ago
return true;
}
3 years ago
fromGasRefillModel(GasRefillModel model) {
3 years ago
id = model.id;
userId = model.userId;
clientName = model.clientName;
title = model.title;
3 years ago
status = model.status != null ? Lookup.fromStatus(model.status!) : null;
details = model.details
?.map<GasRefillDetails>((e) => GasRefillDetails.fromDetails(e))
.toList();
3 years ago
}
3 years ago
factory GasRefillModel.fromJson(Map<String, dynamic> parsedJson) {
3 years ago
List<GasRefillDetails> details = [];
3 years ago
if (parsedJson["details"] != null) {
3 years ago
List list = parsedJson["details"];
details = list.map((e) => GasRefillDetails.fromJson(e)).toList();
}
return GasRefillModel(
id: parsedJson["id"],
userId: parsedJson["uid"],
title: parsedJson["title"],
clientName: parsedJson["client"],
3 years ago
status: Lookup.fromJson(parsedJson["status"]),
3 years ago
details: details,
);
}
}