addItem method

void addItem(
  1. String id,
  2. String itemText, {
  3. int? location,
})

API to add item (add item in a specific location, this is optional).

Parameters:
id Unique ID to be set. itemText String to be set. 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 the ID or value is null. Throws an ArgumentError if the same ID is used in Items.

Implementation

void addItem(String id, String itemText,{int? location}) {
  location ??= items!.length -1;
  if (existItem(id)) {
    throw ArgumentError("addItem : same ID is used.");
  } else if (itemText.isEmpty) {
    throw ArgumentError("addItem : You must set value.");
  } else if (location < 0 || location > (items?.length)!-1) {
    throw ArgumentError("addItem : location is abnormal.");
  }
  SheetItem sheetItem = SheetItem(id: id,sValue: itemText);
  items?.insert(location+1, sheetItem);
}