Reputation: 21
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? 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
Upvotes: 2
Views: 1392
Reputation: 997
use 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);
Upvotes: 2