Плагин Flutter webview и используйте javascript для печати веб-страницы, но только javascript не работает в webview. Пожалуйста, помогите решить эту проблему.
Код флаттера:
Future<Null> _launchInWebViewWithJavaScript(String url) async {
if (await canLaunch(url)) {
await launch(
url,
forceSafariVC: true,
forceWebView: false,
enableJavaScript: true,
);
} else {
throw 'Could not launch $url';
}
}
Код веб-страницы (php, javascript и html):
<?php
$qrString = $_GET['qrString'];
$tableNumber = $_GET['tableNumber'];
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>receipt</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/3.0.3/normalize.css">
<link rel="stylesheet" href="../paper.css">
<style>
@page { size: 75mm 100mm } /* output size */
body.receipt .sheet { width: 58mm; height: 100mm } /* sheet size */
@media print { body.receipt { width: 58mm } } /* fix for Chrome */
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
</head>
<body class="receipt">
<section class="sheet padding-10mm">
<?php echo '<h1>檯號: '.$tableNumber. '</h1><br>' ?>
<img id='barcode'
src=<?php echo 'https://api.qrserver.com/v1/create-qr-code/?data=' .$qrString. '&size=300x300' ?>
alt=""
title="HELLO"
width="300"
height="300" />
</section>
</body>
<script type="text/javascript">
<!--
window.print();
</script>
</html>
Веб-страница работает нормально с браузером Chrome и Safari.
![enter image description here](https://i.stack.imgur.com/m5Zei.png)