buildImage method

Future<Uint8List?> buildImage(
  1. GlobalKey<State<StatefulWidget>> globalKey,
  2. double quality
)

Implementation

Future<Uint8List?> buildImage(GlobalKey globalKey, double quality) async {
  try {
    // Capturamos el widget como imagen (ui.Image)
    RenderRepaintBoundary boundary = globalKey.currentContext!.findRenderObject() as RenderRepaintBoundary;
    var image = await boundary.toImage(pixelRatio: quality); // Resolución de la imagen
    // Convertir a bytes
    ByteData? byteData = await image.toByteData(format: ImageByteFormat.png);
    return byteData!.buffer.asUint8List();
  } catch (e) {
    throw 'buildImage: ${e.toString()}';
  }
}