[英]Capture screenshots of websites with Flutter
Is there a way or package to capture screenshots of a website with Flutter framework and get the image to display it in th UI (like the example bellow)?有没有办法或 package 捕获具有 Flutter 框架的网站的屏幕截图并获取图像以在 UI 中显示它(如下例所示)?
Code Example:代码示例:
import 'dart:io';
import 'package:flutter/material.dart';
class SidePage extends StatefulWidget {
const SidePage({Key? key}) : super(key: key);
@override
State<SidePage> createState() => _SidePageState();
}
class _SidePageState extends State<SidePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
width: 100,
height: 100,
decoration: BoxDecoration(
image: DecorationImage(
image: FileImage( File( ' '),),
fit: BoxFit.fill,
),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10),
bottomLeft: Radius.circular(10))),
),
Container(
width: 200,
height: 100,
decoration: BoxDecoration(
color: Color.fromARGB(255, 73, 73, 73),
borderRadius: BorderRadius.only(
topRight: Radius.circular(10),
bottomRight: Radius.circular(10))),
alignment: Alignment.center,
child: Text(
'Page Title',
style: TextStyle(color: Colors.white),
),
),
],
),
SizedBox(
height: 30,
),
ElevatedButton(
onPressed: () {
//what can I do here t get a screen shot for the web page?
},
child: Text('Get Image'))
]),
);
}
}
When user press "get image" button it get a screenshot for the web page by the link..当用户按下“获取图像”按钮时,它会通过链接获取 web 页面的屏幕截图。
Image for desired result:所需结果的图像:
you can use this screenshot package https://pub.dev/packages/screenshot and after installing it, here's how you gonna add in the onPressed() fuc:你可以使用这个截图 package https://pub.dev/packages/screenshot并且在安装它之后,你将如何添加 onPressed() fuc:
ElevatedButton(
onPressed: () {
screenshotController
.capture(delay: Duration(milliseconds: 10))
.then((capturedImage) async {
ShowCapturedWidget(context, capturedImage!);
}).catchError((onError) {
print(onError);
});
},
child: Text('Get Image'))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.