getRenderTexture method

RenderTexture getRenderTexture()

Implementation

RenderTexture getRenderTexture() {
  if (_gradientTexture == null) {
    _textureCacheKey = _createTextureCacheKey();
    _gradientTexture = _gradientTextureCache.getObject(_textureCacheKey!);
  }

  if (_gradientTexture == null) {
    final canvas = CanvasElement(width: 1, height: GRADIENT_TEXTURE_SIZE);
    final canvasGradient =
        canvas.context2D.createLinearGradient(0, 0, 0, GRADIENT_TEXTURE_SIZE);
    _colorStops.forEach(
        (cs) => canvasGradient.addColorStop(cs.offset, color2rgba(cs.color)));
    canvas.context2D.fillStyle = canvasGradient;
    canvas.context2D.fillRect(0, 0, 1, GRADIENT_TEXTURE_SIZE);
    _gradientTexture = RenderTexture.fromCanvasElement(canvas);
    _gradientTextureCache.addObject(_textureCacheKey!, _gradientTexture!);
  }

  return _gradientTexture!;
}