flutter_inappwebview
flutter_inappwebview copied to clipboard
takeScreenshot can not capturing when the initial size height is set to 2731 or higher. (Only iOS)
- [x] I have read the Get Started - Installation section
- [x] I have read and done the Get Started - Setup Android section
- [x] I have read and done the Get Started - Setup iOS section
- [x] I have already searched for the same problem
Environment
| Technology | Version |
|---|---|
| Flutter version | 2.0.3 |
| Plugin version | 5.3.2 |
| Android version | |
| iOS version | 14.4 |
| Xcode version | 12.4 |
Device information: iPhone 12 Pro (mobile) (com.apple.CoreSimulator.SimRuntime.iOS-14-4)
Description
Expected behavior: takeScreeshot can capture correctly even if the initial size height exceeds 2731. (I want to get a screenshot of full size.)
Current behavior: takeScreeshot can capturing when the initial size height is set to 2730 or lower but takeScreenshot can not capturing when the initial size height is set to 2731 or higher. (Only iOS) (Android is normal)
Steps to reproduce
- Execute the following code and press the "Run HeadlessInAppWebView" button
Stacktrace/Logcat
No error has occurred.
import 'dart:async';
import 'dart:io';
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
Future main() async {
WidgetsFlutterBinding.ensureInitialized();
// await Permission.camera.request();
// await Permission.microphone.request();
// await Permission.storage.request();
if (Platform.isAndroid) {
await AndroidInAppWebViewController.setWebContentsDebuggingEnabled(true);
var swAvailable = await AndroidWebViewFeature.isFeatureSupported(
AndroidWebViewFeature.SERVICE_WORKER_BASIC_USAGE);
var swInterceptAvailable = await AndroidWebViewFeature.isFeatureSupported(
AndroidWebViewFeature.SERVICE_WORKER_SHOULD_INTERCEPT_REQUEST);
if (swAvailable && swInterceptAvailable) {
AndroidServiceWorkerController serviceWorkerController =
AndroidServiceWorkerController.instance();
serviceWorkerController.serviceWorkerClient = AndroidServiceWorkerClient(
shouldInterceptRequest: (request) async {
print(request);
return null;
},
);
}
}
runApp(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) => HeadlessInAppWebViewExampleScreen(),
});
}
}
class HeadlessInAppWebViewExampleScreen extends StatefulWidget {
@override
_HeadlessInAppWebViewExampleScreenState createState() =>
new _HeadlessInAppWebViewExampleScreenState();
}
class _HeadlessInAppWebViewExampleScreenState
extends State<HeadlessInAppWebViewExampleScreen> {
HeadlessInAppWebView? headlessWebView;
String url = "";
@override
void initState() {
super.initState();
headlessWebView = new HeadlessInAppWebView(
initialUrlRequest: URLRequest(url: Uri.parse("https://flutter.dev")),
// OK pattern
// initialSize: Size(390, 2730), // Screenshots cannot be taken correctly if height is 2731
// NG pattern
initialSize: Size(390, 2731), // Screenshots cannot be taken correctly if height is 2731
initialOptions: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(),
),
onWebViewCreated: (controller) {
print('HeadlessInAppWebView created!');
},
onConsoleMessage: (controller, consoleMessage) {
print("CONSOLE MESSAGE: " + consoleMessage.message);
},
onLoadStart: (controller, url) async {
print("onLoadStart $url");
setState(() {
this.url = url.toString();
});
},
onLoadStop: (controller, url) async {
print("onLoadStop $url");
// ---- start take Screenshot code ----
Uint8List? screenshotBytes = await controller.takeScreenshot();
showDialog(
context: context,
builder: (context) {
return AlertDialog(
content: screenshotBytes != null ? Image.memory(screenshotBytes) : Text("data nothing"),
);
},
);
// ---- end take Screenshot code ----
setState(() {
this.url = url.toString();
});
},
onUpdateVisitedHistory: (controller, url, androidIsReload) {
print("onUpdateVisitedHistory $url");
setState(() {
this.url = url.toString();
});
},
);
}
@override
void dispose() {
super.dispose();
headlessWebView?.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
"HeadlessInAppWebView",
)),
body: SafeArea(
child: Column(children: <Widget>[
Container(
padding: EdgeInsets.all(20.0),
child: Text(
"CURRENT URL\n${(url.length > 50) ? url.substring(0, 50) + "..." : url}"),
),
Center(
child: ElevatedButton(
onPressed: () async {
await headlessWebView?.dispose();
await headlessWebView?.run();
},
child: Text("Run HeadlessInAppWebView")),
),
Center(
child: ElevatedButton(
onPressed: () {
headlessWebView?.dispose();
},
child: Text("Dispose HeadlessInAppWebView")),
)
])));
}
}
👋 @dbviewer-zigen
NOTE: This comment is auto-generated.
Are you sure you have already searched for the same problem?
Some people open new issues but they didn't search for something similar or for the same issue. Please, search for it using the GitHub issue search box or on the official inappwebview.dev website, or, also, using Google, StackOverflow, etc. before posting a new one. You may already find an answer to your problem!
If this is really a new issue, then thank you for raising it. I will investigate it and get back to you as soon as possible. Please, make sure you have given me as much context as possible! Also, if you didn't already, post a code example that can replicate this issue.
In the meantime, you can already search for some possible solutions online! Because this plugin uses native WebView, you can search online for the same issue adding android WebView [MY ERROR HERE] or ios WKWebView [MY ERROR HERE] keywords.
Following these steps can save you, me, and other people a lot of time, thanks!
The code has already been posted. Do you need anything else?
I have the same problem
I have the same problem。。
same issue
I have encountered the same problem and hope to resolve it as soon as possible
same issue