/*
 * @Author       : WuWei
 * @LastEditors  : WuWei
 * @Date         : 2021-09-02 16:04:23
 * @LastEditTime : 2022-01-19 12:00:09
 * @Description  : Do not edit
 */
import 'dart:async';
import 'dart:typed_data';

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'dart:ui' as ui;

Future<Uint8List?> capturePng(GlobalKey key) async {
  if (key.currentContext!.debugDoingBuild == false) {
    RenderRepaintBoundary boundary =
        key.currentContext!.findRenderObject() as RenderRepaintBoundary;
    ui.Image image = (await boundary.toImage(pixelRatio: 3.0));
    ByteData? byteData = await image.toByteData(format: ui.ImageByteFormat.png);
    Uint8List pngBytes = byteData!.buffer.asUint8List();
    print(pngBytes);
    return pngBytes;
  }
  return null;
}

Future<ui.Image?> captureImage(GlobalKey key) async {
  if (key.currentContext!.debugDoingBuild == false) {
    RenderRepaintBoundary boundary =
        key.currentContext!.findRenderObject() as RenderRepaintBoundary;
    ui.Image image = (await boundary.toImage(pixelRatio: 3.0));
    return image;
  }
  return null;
}
