2

我正在尝试在颤振中使用网络视图。我关注了这篇中型文章,它描述了我们如何使用 Flutter embed webview 创建一个简单的应用程序。

https://medium.com/@ekosuprastyo15/webview-in-flutter-example-a11a24eb617f

我能够成功创建应用程序,但现在该应用程序正在单击按钮打开,如上面的文章所示。

我想要什么- 现在我想创建一个在加载时在 webview 中加载 URL 的应用程序(即用户不必单击任何按钮或链接来打开该 URL)。

到目前为止我们尝试了什么?

我们已经尝试过flutter url_launcher插件和 flutter_webview_plugin插件。

4

2 回答 2

1

添加这个库Flutter WebView

import 'package:webview_flutter/webview_flutter.dart';

return Scaffold(
      appBar: AppBar(
        title: const Text('Flutter WebView example'),
      ),
      body: const WebView(
        initialUrl: 'https://flutter.io',
        javascriptMode: JavascriptMode.unrestricted,
      ),
    );
于 2021-01-16T06:50:12.750 回答
0

如果您想直接打开您想要的网站而不按任何按钮,您应该提供初始网址。但你应该从其他页面 nagivate.push 到这里。就是这样;

import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';

class WebViewExample extends StatefulWidget {

  @override
  WebViewExampleState createState() => WebViewExampleState();
}

class WebViewExampleState extends State<WebViewExample> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("webview"),
      ),
      body: WebView(
        initialUrl: "https://www.google.com/",
        javascriptMode: JavascriptMode.unrestricted,
      ),
    );
  }
}
于 2021-01-16T06:46:27.290 回答