addItem method
API to add item or add item (add item in a specific location, this is optional).
Parameters:
id - Unique ID to be set.
title - Title to be displayed.
price - Price to be set.
extraPrice - If extraPrice is set, extraPrice is displayed instead of price on custom payment sheet.
location - Location to be displayed in AmountBoxControl on custom payment sheet. For this case you need to call the method by using key: value format (location: 2).
Exceptions:
Throws an ArgumentError if ID or title is empty.
Throws an ArgumentError if the same ID is used in other SheetControl.
Throws an ArgumentError if location is invalid or the same ID is used in other SheetControls.
Implementation
void addItem(String id, String title, double price, String extraPrice,{int? location}) {
if(location == null)
{
if (_hasAmountTotal()) {
location = items!.length-1;
} else {
location = items!.length;
}
}
if (id.isEmpty) {
throw ArgumentError("addItem : You must set itemId.");
} else if (title.isEmpty) {
throw ArgumentError("addItem : You must set title.");
} else if (location < 0 || (_hasAmountTotal() && location >= items!.length) || (!_hasAmountTotal() && location > items!.length)) {
throw ArgumentError("addItem : there is abnormal location");
} else if (_getItemIndex(id) > -1) {
throw ArgumentError("addItem : same id is used.");
}
SheetItem sheetItem = SheetItem(id: id,title: title, dValue: price, sValue: extraPrice,sheetItemType: SheetItemType.AMOUNT_ITEM.name.toString());
items?.insert(location, sheetItem);
}