onLoad method

  1. @override
Future<void> onLoad()
override

Called once when the owning component loads. Override to prepare textures or other resources.

Implementation

@override
Future<void> onLoad() async {
  if (_texture != null) {
    return;
  }
  const white = Color(0xffffffff);
  const transparent = Color(0x00ffffff);
  const radius = _textureSize / 2;
  const center = Offset(radius, radius);
  final paint = Paint();
  if (softness > 0) {
    paint.shader = Gradient.radial(
      center,
      radius,
      const [white, white, transparent],
      [0, (1 - softness).clamp(0.0, 0.99), 1],
    );
  } else {
    paint.color = white;
  }
  final recorder = PictureRecorder();
  Canvas(recorder).drawCircle(center, radius, paint);
  _texture = await recorder.endRecording().toImageSafe(
    _textureSize,
    _textureSize,
  );
}