capture function

Future<Uint8List> capture()

Implementation

Future<Uint8List> capture() async {
  // ignore: cast_nullable_to_non_nullable
  final boundary = OneNavigate.photoKey
    .currentContext!
    .findRenderObject() as RenderRepaintBoundary;
  if(boundary.debugNeedsPaint) {
    unawaited(delayed(capture, 1000));
    return Uint8List(0);
  }

  return Task(boundary.toImage)
    .flatMap((final img) => Task(() =>
      img.toByteData(format: ui.ImageByteFormat.png))
    )
    .map((final data) => data!.buffer.asUint8List())
    .run();
}