Created
September 20, 2019 17:01
-
-
Save vferreirati/20cdbcbf7607c7be5367f94c2d6af19f to your computer and use it in GitHub Desktop.
Exemplo de geração de imagem a partir de um widget
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void _onShareReceipt(context) async { | |
final data = await _onCaptureReceipt(); | |
// Utilizando o pacote "esys_flutter_share" para compartilhamento da imagem gerada | |
await Share.file('Comprovante de Venda', 'comprovante.png', data, 'image/png'); | |
} | |
Future<Uint8List> _onCaptureReceipt() async { | |
// _receiptKey é uma GlobalKey que foi atribuida ao Widget pelo qual desejo imprimir | |
RenderRepaintBoundary boundary = _receiptKey.currentContext.findRenderObject(); | |
final image = await boundary.toImage(pixelRatio: 3.0); | |
ByteData byteData = await image.toByteData(format: ui.ImageByteFormat.png); | |
Uint8List pngBytes = byteData.buffer.asUint8List(); | |
return pngBytes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment