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.
54 lines
1.3 KiB
Dart
54 lines
1.3 KiB
Dart
2 years ago
|
import 'package:test_sa/models/gas_refill/gas_refill_details.dart';
|
||
|
import 'package:test_sa/models/status.dart';
|
||
|
|
||
|
class GasRefillModel{
|
||
|
String id;
|
||
|
String userId;
|
||
|
String clientName;
|
||
|
String title;
|
||
|
Status status;
|
||
|
List<GasRefillDetails> details;
|
||
|
|
||
|
GasRefillModel({
|
||
|
this.id,
|
||
|
this.userId,
|
||
|
this.clientName,
|
||
|
this.title,
|
||
|
this.status,
|
||
|
this.details,
|
||
|
});
|
||
|
|
||
|
bool validate(){
|
||
|
if(title == null) return false;
|
||
|
if(status == null) return false;
|
||
|
if(details == null && details.isEmpty) return false;
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
fromGasRefillModel(GasRefillModel model){
|
||
|
id = model.id;
|
||
|
userId = model.userId;
|
||
|
clientName = model.clientName;
|
||
|
title = model.title;
|
||
|
status = Status.fromStatus(model.status);
|
||
|
details = model.details.map((e) => GasRefillDetails.fromDetails(e)).toList();
|
||
|
}
|
||
|
|
||
|
factory GasRefillModel.fromJson(Map<String,dynamic> parsedJson){
|
||
|
List<GasRefillDetails> details = [];
|
||
|
if(parsedJson["details"] != null){
|
||
|
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"],
|
||
|
status: Status.fromJson(parsedJson["status"]),
|
||
|
details: details,
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|