execute method

  1. @override
Future<bool?> execute(
  1. String caller,
  2. String propertyOrFunction,
  3. List arguments
)
override

Implementation

@override
Future<bool?> execute(
    String caller, String propertyOrFunction, List<dynamic> arguments) async {
  /// setter
  if (scope == null) return null;
  var function = propertyOrFunction.toLowerCase().trim();

  switch (function) {
    // selects the item by index
    case "select":
      int index = toInt(elementAt(arguments, 0)) ?? -1;
      if (index >= 0 && index < items.length) {
        var model = items[index];
        if (model != null && model.selected == false) onTap(model);
      }
      return true;

    // de-selects the item by index
    case "deselect":
      int index = toInt(elementAt(arguments, 0)) ?? -1;
      if (index >= 0 && _dataset != null && index < _dataset!.length) {
        var model = items[index];
        if (model != null && model.selected == true) onTap(model);
      }
      return true;

    // move an item
    case "move":
      moveItem(toInt(elementAt(arguments, 0)) ?? 0,
          toInt(elementAt(arguments, 1)) ?? 0);
      return true;

    // delete an item
    case "delete":
      deleteItem(toInt(elementAt(arguments, 0)));
      return true;

    // add an item
    case "insert":
      insertItem(
          toStr(elementAt(arguments, 0)), toInt(elementAt(arguments, 1)));
      return true;

    // de-selects the item by index
    case "clear":
      onTap(null);
      return true;
  }
  return super.execute(caller, propertyOrFunction, arguments);
}