Imran Khan
Imran Khan

Reputation: 41

Take Screenshot in Flutter web

How to take a screenshot of a widget in Flutter web?

There is RenderRepaintBoundary Widget which can be used for Mobile and iOS but It is giving error for Web.

Upvotes: 4

Views: 1540

Answers (2)

Tudor Axinte
Tudor Axinte

Reputation: 41

Firstly, import:

import 'dart:html';
import 'package:screenshot/screenshot.dart';

Then, it's as easy as:

   screenshotController.capture().then((Uint8List? value) {
      final _base64 = base64Encode(value!);
      final anchor =
          AnchorElement(href: 'data:application/octet-stream;base64,$_base64')
            ..download = "image.png"
            ..target = 'blank';
    
      document.body!.append(anchor);
      anchor.click();
      anchor.remove();
    });

There you go - saving / downloading an image using flutter web!

Upvotes: 4

You can use it as usual if you set the --web-renderer canvaskit flag when building/running your web app.

Upvotes: 0

Related Questions