How to screen record particular widget in flutter?

Viewed 4829

Currently, I'm using a flutter screen recorder plugin(https://pub.dev/packages/flutter_screen_recording) to record the screen, Actually, this plugin records the full screen of the mobile.

But my requirement is to record only a particular widget or a particular section of the screen, For example in the video call app there are two users in the screen, I just want to record only the opposite user video only.

So Is there any workaround or solution available for this, Please guide.

2 Answers

2021 Solution

There is a fairly new package called screen_recorder that can be used for exactly this.

Here's the example:

ScreenRecorder(
  height: 200,
  width: 200,
  background: Colors.white,
  controller: ScreenRecorderController(
    pixelRatio: 0.5,
    skipFramesBetweenCaptures: 2,
  ),
  child: // child which should be recorded
);

The only downsides are that it can't record platform views like the camera or a Google Maps widget and the recording must have a background color (so you can't record with a transparent background).

I was facing a similar issue while taking screenshots as I was getting a blank or black screen while taking a screenshot. But then using this package solved that problem https://pub.dev/packages/native_screenshot

You can simply run this function to take the screenshot of your stream:

Future<void> _capturePng() async {
    String path = await NativeScreenshot.takeScreenshot();
    print(path);
  }

You can find the complete code here: https://github.com/Meherdeep/agora-videocall-demo

Related