Интересно, возможно ли сделать снимок веб-просмотра?
Вот что я попробовал:
например, с webview_flutter 0.1.0 + 1 :
static GlobalKey previewContainer = new GlobalKey();
...
new RaisedButton(
onPressed: takeScreenShot,
child: const Text('Take a Screenshot'),
),
...
takeScreenShot() async{
RenderRepaintBoundary boundary = previewContainer.currentContext.findRenderObject();
ui.Image image = await boundary.toImage();
final directory = (await getApplicationDocumentsDirectory()).path;
ByteData byteData = await image.toByteData(format: ui.ImageByteFormat.png);
Uint8List pngBytes = byteData.buffer.asUint8List();
File imgFile = new File(directory+'/screenshot.png');
imgFile.writeAsBytes(pngBytes);
//then, save the png image file in Firebase storage : OKAY
}
Сначала я попытался сделать экран печати из простой кнопки материала: ОК, это работает
RepaintBoundary(
key: previewContainer,
child:
MaterialButton(
child: const Text('Test'),
textColor: Colors.white,
color: Colors.blue,
),
),
Но когда я пытаюсь сделать экран печати изwebview, он не работает, сохраненное изображение пустое (всего несколько байтов):
RepaintBoundary(
key: previewContainer,
child:
new SizedBox(
height: 280.0,
width: 280.0,
child: WebView(
initialUrl: 'https://flutter.io',
javaScriptMode: JavaScriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController) {
_controller.complete(webViewController);
},
)
),
)
Есть идеи?
или есть другой способ, чем RepaintBoundary для захвата изображения в формате png?