如何在后台运行时使用flutter应用程序截屏

问题描述

我正在尝试制作一个 Flutter应用,该应用在后台中运行时需要屏幕截图,当我从 firebase 可以帮助我解决这个问题吗?或至少教程的某些链接仅当应用程序收到通知时,才触发屏幕截图) 我曾尝试到处搜寻,也遇到媒体投影,但这仅适用于android studio 如果有人帮我解决这个问题,那真是太好了,因为我是编程新手,对此我不太了解。谢谢

解决方法

使用RenderRepaintBoundary

var repaintScreen = new GlobalKey();

//这是您要为其截屏或说要捕获图像的部分

RepaintBoundary(
  key: repaintScreen,child: Container(
  )
),RenderRepaintBoundary boundary =
    repaintScreen.currentContext.findRenderObject();

prefix0.Image image = await boundary.toImage();
final directory = (await getApplicationDocumentsDirectory()).path;
ByteData byteData =
    await image.toByteData(format: prefix0.ImageByteFormat.png);
Uint8List pngBytes = byteData.buffer.asUint8List();
print(pngBytes);
File imgFile = new File('$directory/poct.jpeg');
imgFile.writeAsBytes(pngBytes);