initShaders static method

dynamic initShaders()

Implementation

static initShaders() async {
  if (_isInitializing) {
    return;
  }
  _isInitializing = true;
  for (int i = 0; i < 5; i++) {
    double size = 5.0 + i;
    ui.PictureRecorder recorder = ui.PictureRecorder();
    Canvas imageCanvas = Canvas(recorder);
    final paint = Paint()..color = CDKTheme.white;
    imageCanvas.drawRect(Rect.fromLTWH(0, 0, size, size), paint);
    imageCanvas.drawRect(Rect.fromLTWH(size, size, size, size), paint);
    paint.color = CDKTheme.grey100;
    imageCanvas.drawRect(Rect.fromLTWH(size, 0, size, size), paint);
    imageCanvas.drawRect(Rect.fromLTWH(0, size, size, size), paint);
    int s = (size * 2).toInt();

    _sizes.add(size);

    ui.Image? gridImage = await recorder.endRecording().toImage(s, s);
    _shaders.add(ui.ImageShader(
      gridImage,
      TileMode.repeated,
      TileMode.repeated,
      // ignore: flutter_format_ignore
      Float64List.fromList([
        1,
        0,
        0,
        0,
        0,
        1,
        0,
        0,
        0,
        0,
        1,
        0,
        0,
        0,
        0,
        1,
      ]),
    ));
  }

  _isInitializing = false;
  _initialized = true;
}