generateImage method

void generateImage()

todo pending this function is used to generate random image for testing ui without adding images in asset folder

Implementation

void generateImage() async {
  final Random rd = new Random();
  double kCanvasSize = 500;
  final color = Colors.primaries[rd.nextInt(Colors.primaries.length)];

  final recorder = ui.PictureRecorder();
  final canvas = Canvas(recorder,
      Rect.fromPoints(Offset(0.0, 0.0), Offset(kCanvasSize, kCanvasSize)));

  final stroke = Paint()
    ..color = Colors.grey
    ..style = PaintingStyle.stroke;

  canvas.drawRect(Rect.fromLTWH(0.0, 0.0, kCanvasSize, kCanvasSize), stroke);

  final paint = Paint()
    ..color = color
    ..style = PaintingStyle.fill;

  canvas.drawCircle(
      Offset(
        rd.nextDouble() * kCanvasSize * 0.5,
        rd.nextDouble() * kCanvasSize * 0.5,
      ),
      70.0,
      paint);

  final picture = recorder.endRecording();
  final img = await picture.toImage(200, 200);
  final pngBytes = await img.toByteData(format: ImageByteFormat.png);
  /*  setState(() {
    imgBytes = pngBytes!;
  });*/
}