{"id":15008486,"url":"https://github.com/sachinganesh/screenshot","last_synced_at":"2025-05-16T13:06:19.732Z","repository":{"id":34132829,"uuid":"170084711","full_name":"SachinGanesh/screenshot","owner":"SachinGanesh","description":"Flutter Screenshot Library","archived":false,"fork":false,"pushed_at":"2024-06-08T15:03:56.000Z","size":3140,"stargazers_count":362,"open_issues_count":64,"forks_count":143,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-09T08:05:49.085Z","etag":null,"topics":["dart","dartlang","flutter","flutter-plugin"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/screenshot","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SachinGanesh.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-02-11T07:18:37.000Z","updated_at":"2025-04-09T05:21:15.000Z","dependencies_parsed_at":"2024-05-14T07:44:47.238Z","dependency_job_id":"b7998e46-bcf6-487f-ae5d-9edaa86a7dd0","html_url":"https://github.com/SachinGanesh/screenshot","commit_stats":{"total_commits":40,"total_committers":10,"mean_commits":4.0,"dds":0.725,"last_synced_commit":"e6165a8fd785ec69882766927094104121b6c84e"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SachinGanesh%2Fscreenshot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SachinGanesh%2Fscreenshot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SachinGanesh%2Fscreenshot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SachinGanesh%2Fscreenshot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SachinGanesh","download_url":"https://codeload.github.com/SachinGanesh/screenshot/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247999859,"owners_count":21031046,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dart","dartlang","flutter","flutter-plugin"],"created_at":"2024-09-24T19:19:02.152Z","updated_at":"2025-04-09T08:05:54.124Z","avatar_url":"https://github.com/SachinGanesh.png","language":"Dart","readme":" \u003cimg src=\"https://github.com/SachinGanesh/screenshot/raw/master/assets/sc.png\" alt=\"screenshot\"/\u003e\n\nA simple package to capture widgets as Images. Now you can also capture the widgets that are not rendered on the screen!\n\nThis package wraps your widgets inside [RenderRepaintBoundary](https://docs.flutter.io/flutter/rendering/RenderRepaintBoundary-class.html)\n\n[Source](https://stackoverflow.com/a/51118088)\n\n| | | \n| :---: | :---: |\n|\u003cimg src=\"https://github.com/SachinGanesh/screenshot/raw/master/assets/screenshot.gif\" alt=\"screenshot\"/\u003e|\u003cp\u003e\u0026nbsp; Capture a `widget`:\u003c/p\u003e\u003cimg src=\"https://github.com/SachinGanesh/screenshot/raw/master/assets/code1.png\" alt=\"screenshot\"/\u003e\u003chr\u003e\u003cp\u003e\u0026nbsp;Capture an `invisible widget` (a widget which is not part of the widget tree):\u003c/p\u003e\u003cimg src=\"https://github.com/SachinGanesh/screenshot/raw/master/assets/code2.png\" alt=\"screenshot\"/\u003e|\n\n---\n## Getting Started\n\nThis handy package can be used to capture any Widget including full screen screenshots \u0026 individual widgets like `Text()`.\n\n1) Create Instance of `Screenshot Controller`\n\n```dart\nclass _MyHomePageState extends State\u003cMyHomePage\u003e {\n  int _counter = 0;\n  Uint8List _imageFile;\n\n  //Create an instance of ScreenshotController\n  ScreenshotController screenshotController = ScreenshotController(); \n\n  @override\n  void initState() {\n    // TODO: implement initState\n    super.initState();\n  }\n  ...\n}\n```\n2) Wrap the widget that you want to capture inside `Screenshot` Widget. Assign the controller to `screenshotController` that you have created earlier\n\n```dart\nScreenshot(\n    controller: screenshotController,\n    child: Text(\"This text will be captured as image\"),\n),\n```\n\n3) Take the screenshot by calling `capture` method. This will return a `Uint8List`\n\n```dart\nscreenshotController.capture().then((Uint8List image) {\n    //Capture Done\n    setState(() {\n        _imageFile = image;\n    });\n}).catchError((onError) {\n    print(onError);\n});\n```\n---\n## Capturing Widgets that are not in the widget tree\n\nYou can capture invisible widgets by calling `captureFromWidget` and passing a widget tree to the function\n\n```dart\nscreenshotController\n      .captureFromWidget(Container(\n          padding: const EdgeInsets.all(30.0),\n          decoration: BoxDecoration(\n            border:\n                Border.all(color: Colors.blueAccent, width: 5.0),\n            color: Colors.redAccent,\n          ),\n          child: Text(\"This is an invisible widget\")))\n      .then((capturedImage) {\n    // Handle captured image\n  });\n\n```\n\n---\n\n## Capturing a List Widget\n\nYou can capture a long Invisible widgets by using `captureFromLongWidget` function.\n\n\n\n```dart\nvar randomItemCount = Random().nextInt(100);\n\n///\n/// Step 1: Create Long widget using Column.\n///\n\nvar myLongWidget = Builder(builder: (context) {\n  return Container(\n      padding: const EdgeInsets.all(30.0),\n      decoration: BoxDecoration(\n        border:\n            Border.all(color: Colors.blueAccent, width: 5.0),\n        color: Colors.redAccent,\n      ),\n      ///\n      /// Note: Do not use Scrolling widget, instead place your children in Column. \n      ///  \n      /// Do not use widgets like 'Expanded','Flexible',or 'Spacer'\n      ///\n      child: Column(\n        mainAxisSize: MainAxisSize.min,\n        children: [\n          for (int i = 0; i \u003c randomItemCount; i++)\n            Text(\"Tile Index $i\"),\n        ],\n      ));\n});\n\n///\n/// Step 2: \n///    Use `captureFromLongWidget` function for taking screenshot.\n///\nscreenshotController\n      .captureFromLongWidget(\n          InheritedTheme.captureAll(\n            context, \n            Material(\n              child: myLongWidget,\n            ),\n          ),\n          delay: Duration(milliseconds: 100),\n          context: context,\n\n\n          ///\n          /// Additionally you can define constraint for your image.\n          ///\n          /// constraints: BoxConstraints(\n          ///   maxHeight: 1000,\n          ///   maxWidth: 1000,\n          /// )\n      )\n      .then((capturedImage) {\n    // Handle captured image\n  });\n\n```\n\n\n---\n## Saving images to Specific Location\nFor this you can use `captureAndSave` method by passing directory location. By default, the captured image will be saved to Application Directory. Custom paths can be set using **path parameter**. Refer [path_provider](https://pub.dartlang.org/packages/path_provider)\n\n### Note\n\n\u003eMethod `captureAndSave` is not supported for `web`. \n\n\n```dart\nfinal directory = (await getApplicationDocumentsDirectory ()).path; //from path_provide package\nString fileName = DateTime.now().microsecondsSinceEpoch;\npath = '$directory';\n\nscreenshotController.captureAndSave(\n    path //set path where screenshot will be saved\n    fileName:fileName \n);\n```\n---\n## Saving images to Gallery\nIf you want to save captured image to Gallery, Please use https://github.com/hui-z/image_gallery_saver\nExample app uses the same to save screenshots to gallery.\n\n---\n\n## Sharing Captured Images \n\n```dart\nawait _screenshotController.capture(delay: const Duration(milliseconds: 10)).then((Uint8List image) async {\n      if (image != null) {\n        final directory = await getApplicationDocumentsDirectory();\n        final imagePath = await File('${directory.path}/image.png').create();\n        await imagePath.writeAsBytes(image);\n\n        /// Share Plugin\n        await Share.shareFiles([imagePath.path]);\n      }\n    });\n```\n\n---\n## Note:\nCaptured image may look pixelated. You can overcome this issue by setting value for **pixelRatio** \n\n\u003eThe pixelRatio describes the scale between the logical pixels and the size of the output image. It is independent of the window.devicePixelRatio for the device, so specifying 1.0 (the default) will give you a 1:1 mapping between logical pixels and the output pixels in the image.\n\n\n```dart\ndouble pixelRatio = MediaQuery.of(context).devicePixelRatio;\n\nscreenshotController.capture(\n    pixelRatio: pixelRatio //1.5\n)\n```\n---\nSometimes rastergraphics like images may not be captured by the plugin with default configurations. The issue is discussed [here](https://api.flutter.dev/flutter/flutter_driver/FlutterDriver/screenshot.html). \n\n```\n...screenshot is taken before the GPU thread is done rasterizing the frame \nso the screenshot of the previous frame is taken, which is wrong.\n```\n\nThe solution is to add a small delay before capturing. \n\n```dart\nscreenshotController.capture(delay: Duration(milliseconds: 10))\n```\n---\n## Known Issues\n- **`Platform Views are not supported. (Example: Google Maps, Camera etc)`[issue](https://github.com/flutter/flutter/issues/83856)**\n---","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsachinganesh%2Fscreenshot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsachinganesh%2Fscreenshot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsachinganesh%2Fscreenshot/lists"}