在寻找了很久关于如何拍摄Webview截图的方法后,我发现了这个包----------。本机截图.
问题是,它在调试模式下可以工作,但在生产模式下不能工作--即使使用pub.dev中发布的例子。
我已经在android清单中添加了所需的权限,但仍然无法工作。
我已经把这个问题报告给了开发人员,仍然在等待答复。我想知道这里是否有人能帮助我。
我需要帮助使这个工作。所有的帮助是感激的。谢谢你的帮助。
你可以使用我的插件 翩翩起舞_内页浏览,这是一个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),
);
},
);
},
))
])));
}
}