invokeBindingMethod method

  1. @override
dynamic invokeBindingMethod(
  1. String method,
  2. List args
)
override

Implementation

@override
invokeBindingMethod(String method, List args) {
  // @NOTE: Bridge not guarantee that input type number is double.
  switch (method) {
    case 'arc': return arc(
        castToType<num>(args[0]).toDouble(),
        castToType<num>(args[1]).toDouble(),
        castToType<num>(args[2]).toDouble(),
        castToType<num>(args[3]).toDouble(),
        castToType<num>(args[4]).toDouble(),
        anticlockwise : args[5] == 1 ? true : false);
    case 'arcTo':  return arcTo(
        castToType<num>(args[0]).toDouble(),
        castToType<num>(args[1]).toDouble(),
        castToType<num>(args[2]).toDouble(),
        castToType<num>(args[3]).toDouble(),
        castToType<num>(args[4]).toDouble()
    );
    case 'fillRect': return fillRect(
        castToType<num>(args[0]).toDouble(),
        castToType<num>(args[1]).toDouble(),
        castToType<num>(args[2]).toDouble(),
        castToType<num>(args[3]).toDouble()
    );
    case 'clearRect': return clearRect(
        castToType<num>(args[0]).toDouble(),
        castToType<num>(args[1]).toDouble(),
        castToType<num>(args[2]).toDouble(),
        castToType<num>(args[3]).toDouble());
    case 'strokeRect': return strokeRect(
        castToType<num>(args[0]).toDouble(),
        castToType<num>(args[1]).toDouble(),
        castToType<num>(args[2]).toDouble(),
        castToType<num>(args[3]).toDouble());
    case 'fillText':
      double maxWidth = castToType<num>(args[3]).toDouble();
      if (!maxWidth.isNaN) {
        return fillText(
            castToType<String>(args[0]),
            castToType<num>(args[1]).toDouble(),
            castToType<num>(args[2]).toDouble(),
            maxWidth: maxWidth);
      } else {
        return fillText(castToType<String>(args[0]),
          castToType<num>(args[1]).toDouble(),
          castToType<num>(args[2]).toDouble());
      }
    case 'strokeText':
      double maxWidth = castToType<num>(args[3]).toDouble();
    if (!maxWidth.isNaN) {
      return strokeText(castToType<String>(args[0]),
          castToType<num>(args[1]).toDouble(),
          castToType<num>(args[2]).toDouble(),
          maxWidth: maxWidth);
    } else {
      return strokeText(castToType<String>(args[0]),
          castToType<num>(args[1]).toDouble(),
          castToType<num>(args[2]).toDouble());
    }
    case 'save': return save();
    case 'restore': return restore();
    case 'beginPath': return beginPath();
    case 'bezierCurveTo': return bezierCurveTo(
        castToType<num>(args[0]).toDouble(),
        castToType<num>(args[1]).toDouble(),
        castToType<num>(args[2]).toDouble(),
        castToType<num>(args[3]).toDouble(),
        castToType<num>(args[4]).toDouble(),
        castToType<num>(args[5]).toDouble());
    case 'clip':
      PathFillType fillType = castToType<String>(args[0]) == EVENODD ? PathFillType.evenOdd : PathFillType.nonZero;
      return clip(fillType);
    case 'closePath': return closePath();
    case 'drawImage':
      BindingObject imageElement = BindingBridge.getBindingObject(args[0]);
      if (imageElement is ImageElement) {
        double sx = 0.0,
            sy = 0.0,
            sWidth = 0.0,
            sHeight = 0.0,
            dx = 0.0,
            dy = 0.0,
            dWidth = 0.0,
            dHeight = 0.0;

        if (args.length == 3) {
          dx = castToType<num>(args[1]).toDouble();
          dy = castToType<num>(args[2]).toDouble();
        } else if (args.length == 5) {
          dx = castToType<num>(args[1]).toDouble();
          dy = castToType<num>(args[2]).toDouble();
          dWidth = castToType<num>(args[3]).toDouble();
          dHeight = castToType<num>(args[4]).toDouble();
        } else if (args.length == 9) {
          sx = castToType<num>(args[1]).toDouble();
          sy = castToType<num>(args[2]).toDouble();
          sWidth = castToType<num>(args[3]).toDouble();
          sHeight = castToType<num>(args[4]).toDouble();
          dx = castToType<num>(args[5]).toDouble();
          dy = castToType<num>(args[6]).toDouble();
          dWidth = castToType<num>(args[7]).toDouble();
          dHeight = castToType<num>(args[8]).toDouble();
        }

        return drawImage(
            args.length,
            imageElement.image,
            sx,
            sy,
            sWidth,
            sHeight,
            dx,
            dy,
            dWidth,
            dHeight);
      }
      break;
    case 'ellipse':
      return ellipse(
          castToType<num>(args[0]).toDouble(),
          castToType<num>(args[1]).toDouble(),
          castToType<num>(args[2]).toDouble(),
          castToType<num>(args[3]).toDouble(),
          castToType<num>(args[4]).toDouble(),
          castToType<num>(args[5]).toDouble(),
          castToType<num>(args[6]).toDouble(),
          anticlockwise : args[7] == 1 ? true : false);
    case 'fill':
       PathFillType fillType = args[0] == EVENODD ? PathFillType.evenOdd : PathFillType.nonZero;
       return fill(fillType);
    case 'lineTo': return lineTo(
      castToType<num>(args[0]).toDouble(),
      castToType<num>(args[1]).toDouble());
    case 'moveTo': return moveTo(
      castToType<num>(args[0]).toDouble(),
      castToType<num>(args[1]).toDouble());
    case 'quadraticCurveTo': return quadraticCurveTo(
        castToType<num>(args[0]).toDouble(),
        castToType<num>(args[1]).toDouble(),
        castToType<num>(args[2]).toDouble(),
        castToType<num>(args[3]).toDouble());
    case 'rect': return rect(
        castToType<num>(args[0]).toDouble(),
        castToType<num>(args[1]).toDouble(),
        castToType<num>(args[2]).toDouble(),
        castToType<num>(args[3]).toDouble());
    case 'rotate': return rotate(castToType<num>(args[0]).toDouble());
    case 'resetTransform': return resetTransform();
    case 'scale': return scale(
        castToType<num>(args[0]).toDouble(),
        castToType<num>(args[1]).toDouble()
    );
    case 'stroke': return stroke();
    case 'setTransform': return setTransform(
        castToType<num>(args[0]).toDouble(),
        castToType<num>(args[1]).toDouble(),
        castToType<num>(args[2]).toDouble(),
        castToType<num>(args[3]).toDouble(),
        castToType<num>(args[4]).toDouble(),
        castToType<num>(args[5]).toDouble()
    );
    case 'transform': return transform(
        castToType<num>(args[0]).toDouble(),
        castToType<num>(args[1]).toDouble(),
        castToType<num>(args[2]).toDouble(),
        castToType<num>(args[3]).toDouble(),
        castToType<num>(args[4]).toDouble(),
        castToType<num>(args[5]).toDouble()
    );
    case 'translate': return translate(
      castToType<num>(args[0]).toDouble(),
      castToType<num>(args[1]).toDouble());
    default: return super.invokeBindingMethod(method, args);
  }
}