Reputation: 41
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
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
Reputation: 372
You can use it as usual if you set the --web-renderer canvaskit
flag when building/running your web app.
Upvotes: 0