请参阅Github 问题/文档:
- 不支持 iframe 嵌入的普通 URL(例如https://google.com,您需要使用
SourceType.urlBypass它)。
webviewController.loadContent(
'https://google.com',
SourceType.urlBypass,
);
Run Code Online (Sandbox Code Playgroud)
完整示例:
import 'package:flutter/material.dart';
import 'package:webviewx/webviewx.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: MyWebViewPage(),
);
}
}
class MyWebViewPage extends StatefulWidget {
@override
_MyWebViewPageState createState() => _MyWebViewPageState();
}
class _MyWebViewPageState extends State<MyWebViewPage> {
late WebViewXController webviewController;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('WebViewX Example'),
),
body: Column(
children: [
WebViewX(
initialContent: 'https://example.com',
// initialSourceType: SourceType.,
onWebViewCreated: (controller) => webviewController = controller,
onWebResourceError: (error) {
print('WebViewX Error: ${error.errorCode}, ${error.description}');
},
// ... other options
width: 400,
height: 400,
),
ElevatedButton(
onPressed: () {
// Load a URL when the button is pressed
webviewController.loadContent(
'https://google.com',
SourceType.urlBypass,
);
},
child: Text('Load Google Website'),
),
ElevatedButton(
onPressed: () {
// Go back in the webview's history
webviewController.goBack();
},
child: Text('Go Back'),
),
ElevatedButton(
onPressed: () {
// Go forward in the webview's history
webviewController.goForward();
},
child: Text('Go Forward'),
),
],
),
);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
607 次 |
| 最近记录: |