toMap method
Implementation
Map<String, dynamic> toMap() {
Map<String, dynamic> res = {
'merchantName': merchantName,
'subtotal': -1,
'tax': -1,
'tip': -1,
};
double subtotal = 0;
items.forEach((element) {
res.addAll(element.toMap());
subtotal += element.amount;
});
if (tax != null || tip != null) {
res['subtotal'] = subtotal;
} else {
return res;
}
if (tax != null) {
res['tax'] = tax;
}
if (tip != null) {
res['tip'] = tip;
}
return res;
}