How to load widget screenshot

51 Views Asked by At

I use a Globalkey to take a screenshot of a child WebView widget of RepaintBoundary. I am able to convert the image data into a Uint8List :

This is the result from the widget capture:

[137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 1, 156, 0, 0, 2, 153, 8, 6, 0, 0, 0, 140, 100, 157, 23, 0, 0, 0, 1, 115, 82, 71, 66, 0, 174, 206, 28, 233, 0, 0, 0, 4, 115, 66, 73, 84, 8, 8, 8, 8, 124, 8, 100, 136, 0, 0, 4, 61, 73, 68, 65, 84, 120, 156, 237, 193, 49, 1, 0, 0, 0, 194, 160, 245, 79, 109, 10, 63, 160, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,....]

RepaintBoundary(
            key: objectKeyRepaint,
            child: WebView(),
               ),





RenderRepaintBoundary? boundary =objectKeyRepaint.currentContext?.findRenderObject() as RenderRepaintBoundary?;
var image = await boundary?.toImage();
ByteData? byteData = await image?.toByteData(format:ImageByteFormat.png);
Uint8List? pngBytes = byteData?.buffer.asUint8List();
widget.imagedata=pngBytes;

I try to load the Uint8List result from a list into an Image.memory widget but nothing shows.

            Expanded(
                child: Container(
                  decoration: BoxDecoration(
                    color: Colors.brown,
                  borderRadius: BorderRadius.vertical(top:Radius.circular(0),bottom: Radius.circular(20)),
                  ),
                  child:Image.memory(widget.allPagesImages.elementAt(index)), //list containing all the Uint8list screenshots
                   ),
                ),
0

There are 0 best solutions below