capturePng static method
Hàm chuyển Widget thành Uint8List
Implementation
static Future<Uint8List> capturePng(GlobalKey globalKey) async {
final RenderRepaintBoundary boundary =
globalKey.currentContext!.findRenderObject() as RenderRepaintBoundary;
final ui.Image image = await boundary.toImage();
final ByteData byteData = await (image.toByteData(
format: ui.ImageByteFormat.png,
) as FutureOr<ByteData>);
final Uint8List pngBytes = byteData.buffer.asUint8List();
return pngBytes;
}