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
{
  if (scope == null) return null;
  var function = propertyOrFunction.toLowerCase().trim();
  switch (function)
  {
    // clear the list
    case "clear":
      int? start = S.toInt(S.item(arguments, 0));
      int? end = S.toInt(S.item(arguments, 1));
      return await clear(start: start, end: end);

    // add to the list
    case "add":
      String? jsonOrXml  = S.toStr(S.item(arguments, 0));
      int index = S.toInt(S.item(arguments, 1)) ?? (data != null ? data!.length : 0);
      if (jsonOrXml != null)
      {
        Data? d = Data.from(jsonOrXml);
        if (data != null)
        {
          if (index > d.length) index = d.length;
          if (index.isNegative) index = 0;
          for (var element in d) {
            data!.insert(index++, element);
          }
        }
        else {
          data = Data.from(d);
        }

        // notify listeners of data change
        notify();
      }
      return true;

    // remove from the list
    case "remove":
      int index = S.toInt(S.item(arguments, 1)) ?? (data != null ? data!.length : 0);
      if (data != null)
      {
        if (index >= data!.length) index = data!.length - 1;
        if (index.isNegative) index = 0;
        data!.removeAt(index);
        notify();
      }
      return true;

    // reverse the list
    case "reverse":
      if (data != null)
      {
        data = data!.reversed;
        notify();
      }
      return true;
  }
  return super.execute(caller, propertyOrFunction, arguments);
}