1

I'm developing a punch clock in a tablet with Flutter Application and I need this functionality.

I know how to make the camera show and the user make a screenshot, but I searched everywhere how to make an automatic self screenshot after 3 seconds and don't find anything.

Someone has an example, tutorial, or experience to make something like this?

wavrik
  • 341
  • 3
  • 11

1 Answers1

1

You can use Timer class to do some action after certain time duration as shown below

Timer(Duration(milliseconds: 3000), () {
    //after 3 seconds this will be called, 
    //once this is called take picture or whatever function you need to do
    takeScreenshot();
  });

And if you want,use this code below to take screenshot as mentioned in this answer Take Screenshot Stackoverflow answer

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();
   print(pngBytes);
   File imgFile =new File('$directory/screenshot.png');
   imgFile.writeAsBytes(pngBytes);
  }

Hope this helps!

ANUP SAJJAN
  • 1,458
  • 13
  • 17