在寻找了很长一段时间如何拍摄Webview截图后,我找到了这个包- native_screenshot。
问题是,它在调试模式下工作,但不能在生产模式下工作-即使在使用pub.dev中发布的示例时也是如此。
我已经向android清单中添加了所需的权限,但仍然无法使其正常工作。
我已经向开发人员报告了这个问题,还在等待答复。我想知道这里是否有人能帮上忙。
我需要帮助才能让它起作用。感谢所有的帮助。谢谢
发布于 2020-06-03 09:07:29
webview_flutter插件没有提供截取WebView屏幕截图的方式或方法。因此,您可以尝试my plugin flutter_inappwebview,它是一个Flutter插件,允许您添加内联WebViews或打开应用程序中的浏览器窗口,它有许多事件、方法和选项来控制WebViews。
要截取屏幕,您可以使用InAppWebViewController.takeScreenshot方法,该方法获取WebView的可视视口的屏幕截图( PNG格式),并返回一个Uint8List。
下面是一个示例,它在页面停止加载时截取WebView的屏幕截图,并显示一个带有相应屏幕截图的警告对话框:
import 'dart:async';
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
Future main() async {
WidgetsFlutterBinding.ensureInitialized();
runApp(new MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
return MaterialApp(initialRoute: '/', routes: {
'/': (context) => InAppWebViewExampleScreen(),
});
}
}
class InAppWebViewExampleScreen extends StatefulWidget {
@override
_InAppWebViewExampleScreenState createState() =>
new _InAppWebViewExampleScreenState();
}
class _InAppWebViewExampleScreenState extends State<InAppWebViewExampleScreen> {
InAppWebViewController webView;
Uint8List screenshotBytes;
@override
void initState() {
super.initState();
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("InAppWebView")),
body: Container(
child: Column(children: <Widget>[
Expanded(
child: InAppWebView(
initialUrl: "https://github.com/flutter",
initialHeaders: {},
initialOptions: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
debuggingEnabled: true),
),
onWebViewCreated: (InAppWebViewController controller) {
webView = controller;
},
onLoadStart: (InAppWebViewController controller, String url) {},
onLoadStop: (InAppWebViewController controller, String url) async {
screenshotBytes = await controller.takeScreenshot();
showDialog(
context: context,
builder: (context) {
return AlertDialog(
content: Image.memory(screenshotBytes),
);
},
);
},
))
])));
}
}https://stackoverflow.com/questions/61305188
复制相似问题