简体   繁体   English

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

[英]how to take screenshot with a flutter app while it is in the background

i am trying to make an flutter app which takes screenshot while running in the background and that too when i push a notification from firebase to the app can someone help me out with this?我正在尝试制作一个flutter 应用程序,该应用程序在后台运行时截取屏幕截图,当我将来自firebase的通知推送到应用程序时,有人可以帮我解决这个问题吗? or atleast some links of the tutorials( screenshot should be triggered only when the app recieves a notification ) i've tried searching everywhere and also came across media projection but it was only for android studio it would be really great if someone helps me with this as i am a newbie in programming and i dont know much about this.thank you或至少教程的一些链接(只有在应用程序收到通知时才应触发屏幕截图)因为我是编程新手,对此我不太了解。谢谢

use RenderRepaintBoundary使用 RenderRepaintBoundary

var repaintScreen = new GlobalKey();

//this for which part you want to take a screen shot or say capture in image //这是您要截屏的部分或说在图像中捕获

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM