addControl method

void addControl(
  1. SheetControl sheetControl, {
  2. int? location,
})

API to add SheetControl (add SheetControl in specific location).

Parameters: sheetControl SheetControl to be set.
The possible values are: AddressControl AmountBoxControl PlainTextControl

location SheetControl location to be displayed 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 sheetControl is null. Throws an ArgumentError if same ID is used in other SheetControls. Throws an ArgumentError if there is no data in AmountBoxControl. Throws an ArgumentError AmountBoxControl.setAmountTotal(double, String) API method should be called when AmountBoxControl is created or updated. If setAmountTotal() is not called, AMOUNT_TOTAL SheetItemType is not the last item in AmountBoxControl.

Implementation

void addControl(SheetControl sheetControl,{int? location}){
  location??= sheetControls!.length;
    if (location < 0 || location > sheetControls!.length) {
      throw ArgumentError("addItem : there is abnormal location.");
    } else if (getSheetControl(sheetControl.controlId!) != null) {
      throw ArgumentError("addControl : same id is used.");
    }

  if(sheetControl.controltype == Controltype.AMOUNTBOX){
    AmountBoxControl amountBoxControl =  sheetControl as AmountBoxControl;
    int lastItemIndex = amountBoxControl.getItems()!.length - 1;
    if (lastItemIndex < 0) {
      throw ArgumentError("addControl : No data in AmountBoxControl.");
    } else if (amountBoxControl.getItems()!.elementAt(lastItemIndex).getSheetItemType() != (SheetItemType.AMOUNT_TOTAL.name)) {
      throw ArgumentError("AMOUNT_TOTAL type must be the last item in AmountBoxControl.");
    }
  }
  sheetControls?.insert(location,sheetControl);

}