android 关于“Flutter WebView Widget”的问题

z4bn682m  于 2023-03-28  发布在  Android
关注(0)|答案(1)|浏览(111)

我想创建一个非常简单的flutter应用程序,显示一个特定的网页(一种“网页到应用程序”的东西)。在应用程序中只有一个Webview小部件。我做的一切都是正确的,应用程序在模拟器中启动并运行,但当我在我的设备上安装它时(我还测试了另外两个设备)我得到这个错误:“err_cache_miss”.我猜错误是从chrome中产生的,因为Chrome实际上是webview。这是我的代码:

import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
  return MaterialApp(
    title: 'My App',
    home: Scaffold(
      appBar: AppBar(
      title: Text('Nextouch By Prevail'),
      ),

    body: WebView(
      initialUrl: 'http://www.google.com',
      javascriptMode: JavascriptMode.unrestricted, // Enable JavaScript
    ),
  ),
);

{\fnSimHei\bord1\shad1\pos(200,288)}
有什么主意吗?谢谢

zlhcx6iw

zlhcx6iw1#

根据你的包,我没有找到Webview:但我设法用下面的代码加载它

import 'package:webview_flutter/webview_flutter.dart';
 
 void main() {
   runApp(const MyApp());
 }
 
 class MyApp extends StatelessWidget {
   const MyApp({super.key});
 
   // This widget is the root of your application.
   @override
   Widget build(BuildContext context) {
     final WebViewController controller =
         WebViewController.fromPlatformCreationParams(
             const PlatformWebViewControllerCreationParams());
     controller
       ..setJavaScriptMode(JavaScriptMode.unrestricted)
       ..loadRequest(Uri.parse('https://flutter.dev'));

 return MaterialApp(
   title: 'My App',
   home: Scaffold(
     appBar: AppBar(
       title: Text('Hello world'),
     ),
     body: WebViewWidget(controller: controller),
   ),
 );
}
}

此处为结果:

相关问题