1

i am trying to find a way to take a screenshot of entire screen. Flutter library is only allowing me to make a screenshot of a widget, but i want a screenshot of entire android.

I did find this link: How to programmatically take a screenshot on Android?

and this is resolwing my problem, but i tried to use that java code as it is in documentation: https://flutter.dev/docs/development/platform-integration/platform-channels?tab=android-channel-java-tab

sadly i am not able to run that code, maybie im making some kind of mistakes? i find a error, while i whas following docs instruction, after that program whas working (not exacly, java whas not able to find my battery, but code whas compiling), and then i copy first answer from that stack link and i tried to pase it in "MainActivity" folder, sadly program whas not working, my "old" java code whas comipilng, from the docs, not the new one.

If you know the solution how to make a photo of entire android screen using some kind of buttor in flutter, or how to implement code from that link into my MainActivity.java folder, please help

Maciek
  • 181
  • 3
  • 12
  • Show us, what have you tried on your code please. – Mvrocha Feb 09 '21 at 16:40
  • i tried ask on flutter discord, thy told me about this first link where someon using java acomplish that, then i whas following docs tutorial how to implement java in flutter, then i did as it is written in the first link, to copy entire block in Activity function in place called "MainActivity,java", but sadly nithing worked :c the old cod from docs whas compiling, even when i copy phase the new one, im trying to find library in flutter, and comend below maybie resolve my problem :D. Thanks for trying to understande me, but (i hope) i did resolve my problem – Maciek Feb 10 '21 at 11:44

2 Answers2

1

Try this package native_screenshot

https://pub.dev/packages/native_screenshot

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

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

You can learn more about this package here

It work fine with Android and IOS

Hope it will be useful

Kab Agouda
  • 6,309
  • 38
  • 32
  • and this library will allow me to take full screenshot of android screen with aplication with some messenger chats, clock on my phone battery etc? oh boy thank you verry much it is resolving my problem, thank you <3 – Maciek Feb 10 '21 at 11:33
  • 1
    oh boy, i whas wrong all along, i did iplement that library, and after changing minSdk it make a screenshot, but only a screenshot of aplication, i mean i cannot make a photo also of a battery and a clock, sadly it is not resolving my problem – Maciek Feb 10 '21 at 12:16
0

You can use screenshot plugin:https://pub.dev/packages/screenshot to take a widget screenshot.

A screenshot is a simple plugin to capture widgets as Images. This plugin wraps your widgets inside RenderRepaintBoundary

Use this package as a library

Add this to your package's pubspec.yaml file:

dependencies: screenshot: ^0.2.0 Now in your Dart code, Import it:

import 'package:screenshot/screenshot.dart';

This handy plugin can be used to capture any Widget including full-screen screenshots & individual widgets like Text().

Create Instance of Screenshot Controller

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;
  File _imageFile;

  //Create an instance of ScreenshotController
  ScreenshotController screenshotController = ScreenshotController(); 

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }
...
}

Wrap the widget that you want to capture inside Screenshot Widget. Assign the controller to screenshotController that you have created earlier

 Screenshot(
      controller: screenshotController,
      child: Text("This text will be captured as image"),
    ),

Take the screenshot by calling the capture method. This will return a File

screenshotController.capture().then((File image) {
 //Capture Done
 setState(() {
     _imageFile = image;
 });
}).catchError((onError) {
 print(onError);
});

Duplicate: How to take a screenshot of the current widget - Flutter

ahmad bajwa
  • 966
  • 2
  • 10
  • 30
  • sadly it is not a solution this library only make screenshot of a specific widget, but i want to make a screnshot of entire android screen with a battery, clock etc – Maciek Feb 09 '21 at 18:59
  • @Maciek you should have mention that you have already tired these libraries. – ahmad bajwa Feb 10 '21 at 09:04
  • 2
    but i did "Flutter library is only allowing me to make a screenshot of a widget, but i want a screenshot of entire android" – Maciek Feb 10 '21 at 11:27
  • @Maciek I mean you should specify which flutter library? – ahmad bajwa Feb 10 '21 at 12:28
  • sadly it hapens to be all the libraries, becous yours, and also "https://pub.dev/packages/native_screenshot" is doing the same thins, with is taking photo of an widget. But i am not good with stacoverflow, can you tell me what specific things i shuld write in my next question to make it more clear? i shuld write names of all those libraries? but i did write that i dont want a photo of an widget, that whas not enought? i am very sorry if that make a problems for you – Maciek Feb 10 '21 at 16:32
  • @Maciek no problem just mention all details and libraries you have tired. – ahmad bajwa Feb 10 '21 at 17:05
  • ok, sorry for inconvenience, i will now ask better questions with more information from the begining – Maciek Feb 12 '21 at 10:24
  • @Maciek no problem. – ahmad bajwa Feb 12 '21 at 11:28
  • @Maciek i have same problem. did you solve that ? – Purya May 15 '22 at 17:08
  • no, I tried to do it for my friend so it whas not that important for me to resolve it, and stack overflow also did not help – Maciek May 19 '22 at 12:52
  • @Purya if you will find solution please give a commet here, so other ppl will know it, thx <3 – Maciek May 19 '22 at 12:53